Apache mod_rewrite匹配部分文件名并返回404

时间:2016-02-11 03:27:07

标签: regex apache .htaccess mod-rewrite

我离开了一个月,我的测试服务器在断电后重新启动,可能是更新版本的apache(2.4.7)和mod_rewrite。现在我的.htaccess文件在此测试服务器上有一个奇怪的行为,但在实时服务器上没有。

以下网址提供" 200 OK"在实时服务器上,但不在测试服务器上。它匹配部分文件名,直到句点,并给出" 404 Not found"

http://192.168.1.1/travel/ - 200 OK
http://192.168.1.1/travel/map/ - 200 OK
http://192.168.1.1/travel/index - 404 Not found
http://192.168.1.1/travel/index.php - 200 OK
http://192.168.1.1/travel/Trip - 404 Not found
http://192.168.1.1/travel/Tri - 200 OK
http://192.168.1.1/travel/trip - 200 OK
http://192.168.1.1/travel/User/yyy/zzz - 404 Not found
http://192.168.1.1/travel/user/yyy/zzz - 200 OK
http://192.168.1.1/travel/Test - 200 OK

这是我的.htaccess文件:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
# RewriteRule ^(.*)$ index.php [L]
RewriteRule . index.php [L]

php_value upload_max_filesize 10M
php_value post_max_size 10M

这是我的travel目录结构:

images/
map/index.php
.htaccess
Blog.class.php
Location.class.php
Trip.class.php
Image.class.php
index.php
User.class.php

测试服务器在Ubuntu 14.04.3 LTS上运行

1 个答案:

答案 0 :(得分:1)

这是因为某些服务器和* nix服务器上的URL区分大小写。

尝试添加NC flag以查看是否有帮助。

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
# RewriteRule ^(.*)$ index.php [L]
RewriteRule . index.php [NC,L]

https://httpd.apache.org/docs/2.4/rewrite/flags.html#flag_nc

或者您也可以尝试使用Multiviews,将其置于顶部。

Options -MultiViews