开发者

.htaccess is not executed when trailing slash is missing

This is the weirdest problem I have encountered. I am using mod_rewrite in .htaccess in Apa开发者_运维百科che/2.2.13 (Linux/SUSE), and it appears to not be called when there is no trailing slash in the URL. I tested by putting garbage in the .htaccess file, and only received 500 errors when the trailing slash was added, but 404 when omitted. I honestly have no idea why.

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]

/name fails with 404
/name/ is successful


The issue is that /name is a file name that apache usually manages to map to the directory /name/, but sometimes this mechanism fails. I've had a remotely similar problem and followed the suggestions to solve the problem according to the Trailing Slash Problem section of the URL Rewriting Guide in Apache's documentation.

I'd think that in your case you could try to add the following lines (I'd suggest right after RewriteEngine On) to your Apache configuration file, if you have access to it:

 RewriteBase    /
 RewriteRule    ^name$  name/  [R]
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜