2012-04-20 173 views
1

结尾的斜杠我有这个htaccess脚本导致错误代码500

Options -Indexes 
Options +FollowSymlinks 

RewriteEngine on 
RewriteBase/
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^(.+)$ /$1.php [L,QSA] 

,所以我可以访问一个页面像example.com/test但是当我尝试去example.com/test/它抛出一个500错误。有人能告诉我需要改变它的工作吗?可能是一个愚蠢的错误。从^(.+)$一个将处理分开斜线

回答

3

更改模式:^(.*[^/])/?$

Options -Indexes +FollowSymlinks 

RewriteEngine on 
RewriteBase/

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^(.*[^/])/?$ /$1.php [L,QSA] 

这两个/test/test/工作 - 两者都将被改写为/test.php

如果你想不同的行为,有/test工作,但有“404 Not Found”错误的/test/(而不是愚蠢的“500服务器端”的错误),您可以使用此:

Options -Indexes +FollowSymlinks 

RewriteEngine on 
RewriteBase/

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}\.php -f 
RewriteRule ^(.+)$ $1.php [L] 

规则以上将检查目标文件是否存在之前进行重写..因此,如果/test.php不存在,则不会发生重写。

+0

非常感谢你 – topherg 2012-04-20 11:58:45