2014-03-02 133 views
0

.htaccess文件:网址重定向到目录之前

RewriteEngine on 

RewriteBase /P5/ 

#existing rule 
#remove the www. 
RewriteCond %{HTTP_HOST} ^www.website.co.uk$ [NC] 

#new Rule 
#if its not a directory 
RewriteCond %{REQUEST_FILENAME} !-d 
#and it has a trailing slash then redirect to URL without slash 
RewriteRule ^(.+)/$ /$1 [L,R=301] 

RewriteRule ^([a-zA-Z0-9_-]+)$ def.php?p=$1 [L] 

这是,如果我访问某些菜单。

例如:家在我的地址栏是这样写:localhost/P5/home,但如果我回家后添加/localhost/P5/home/

它被自动重定向到:localhost/home和页面没有找到出现

任何人都知道这个问题?感谢

回答

-2

,但如果我/回家后添加:localhost/P5/home/它被自动重定向到:localhost/home

嘛当然是的,因为你已经设置/P5/RewriteBase,并为此

RewriteRule ^(.+)/$ /$1 [L,R=301] 

只匹配home/,并且您使用前导斜杠重定向到捕获部分home,因此它变成/home - 并且以斜杠开头的相对URL总是指向您的域,因此整个事情变为http://localhost/home

如果你不想这样 - 那么不要在重写结果前面使用前导斜杠。