为什么我的http身份验证不起作用?

时间:2014-10-21 18:18:40

标签: codeigniter http http-authentication

我为其中一个网站设置了http身份验证。 Web应用程序使用代码点火器和自定义URI路由构建。更改站点的.conf文件后,尝试访问主页以外的任何页面时出现404 Not Found错误。例如,导航到/about(在http身份验证之前工作),不会向404发送消息:

The requested URL /about was not found on this server.

Apache/2.4.7 (Ubuntu) Server at example.com Port 80

为什么apache将请求发送到'/`目录?启用站点的.conf文件(略微适应安全性)如下:

<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.

ServerName example.com  

DirectoryIndex index.php
ServerAdmin webmaster@localhost
DocumentRoot /home/user/codeigniter

# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn

ErrorLog /home/user/logs/codeigniter/error.log
CustomLog /home/user/logs/codeigniter/access.log combined

# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf

<Directory /home/user/codeigniter/>
    # Options Indexes FollowSymLinks Includes ExecCGI
    # AllowOverride All
    # Require all granted
    AuthType Basic
    AuthName "Beta Site"
    # (Following line optional)
    AuthBasicProvider file
    AuthUserFile /var/www/passwd/passwords
    Require user user
</Directory>

1 个答案:

答案 0 :(得分:1)

在目录定义&lt; Directory / home / user / codeigniter&gt;中,您需要更改:

# AllowOverride All

AllowOverride All

并重新启动apache。

如果没有它,文档根目录中的.htaccess文件将无法正常工作,您只能通过uri /index.php/about访问/浏览。