.htaccess通过一切

时间:2014-08-15 09:01:01

标签: apache .htaccess mod-rewrite

我的.htaccess文件遇到了一些问题而且我不知道为什么。它适用于localhost,但在服务器上发布时会传递每个URL。服务器是一个带有apache 2.2的Linux环境。这是我的.htaccess(特别是第6行):

RewriteEngine   On
LogLevel alert rewrite:trace2
RewriteBase     /var/www/html/resurs/
RewriteRule     ^ajaxLogin$                     /core/login/ajaxLogin.php
RewriteRule     ^handleForm$                    /core/form/handler.php
RewriteRule     ^login/$                        /core/login/login.php [L]
RewriteRule             ^logout/$                                               /index.php?logout [L]
RewriteRule     ^shell/uploadedFiles/([a-f0-9()]+)\.(\w)$ - [S=7]
RewriteRule     ^core/login/ajaxLogin\.php|core/form/handler\.php|core/login/login\.php|index\.php\?logout$ - [S=6]
RewriteRule     ^shell/(images|css|javascript)/((\w+)\.(\w+))$   - [S=5]
RewriteRule     ^core/(images|css|javascript)/((\w+)\.(\w+))$   - [S=4]
RewriteRule     ^core/admin/(images|css|javascript)/((\w+)\.(\w+))$   - [S=3]
RewriteRule     ^mods/(\w+)/(images|css|javascript)/((\w+)\.(\w+))$   - [S=2]
RewriteRule     ^index\.php - [S=1]
RewriteRule     ^(?!index\.php\?path)(.+(/.+)*/{0,1})$ /index.php?path=$1 [L,B,NS]

访问my.site/login/时,重写日志会说:

X.X.X.X - - [15/Aug/2014:10:48:01 +0200] [my.site/sid#2b770f4adef0][rid#2b7713535100/initial] (2) init rewrite engine with requested uri /login/
X.X.X.X - - [15/Aug/2014:10:48:01 +0200] [my.site/sid#2b770f4adef0][rid#2b7713535100/initial] (1) pass through /login/

感觉它甚至没有进入我的.htaccess

1 个答案:

答案 0 :(得分:0)

正如您所说,它根本没有读取.htaccess文件,请确保正确设置以下指令:

AccessFileName .htaccess

如果定义了它,它应该在服务器配置(httpd.conf)或该配置文件中的虚拟主机块中。这是Apache将要寻找的文件。默认情况下应该是.htaccess,但如果将其更改为.unicorn,则会在每个目录中检查.unicorn。请参阅the docs

还要确保允许.htaccess覆盖任何内容。如果不允许覆盖任何内容,它甚至不会检查文件中的内容。 AllowOverride必须设置为至少FileInfo。该指令必须位于<directory>块中的服务器配置中:

<Directory />
    AllowOverride FileInfo
</Directory>

再次,请参阅the docs了解详情。

相关问题