2012-01-05 39 views
5

我有以下重写规则:删除斜线如果没有目录与Apache

#remove the www. 
RewriteCond %{HTTP_HOST} ^www.website.co.uk$ [NC] 
RewriteRule ^(.*)$ http://local.website.co.uk/$1 [R=301,L] 

#this removes php extention 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^([^\.]+)$ $1.php [NC,L] 

# stops you accessing url with.php 
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /([^.?\ ]+)\.php 
RewriteRule ^([^.]+)\.php(/.+)?$ /$1%{PATH_INFO} [R=301] 

我想在一个规则,如果有人试图用一个访问的网站,删除结尾的斜线增加。

website.co.uk/cheese/应该重定向到/奶酪

,你可以看到我有一个重定向输尿管镜气压弹道碎石和.php extention的规则,不知道从哪里开始。

我确实在根文件夹中有一个目录,我不想删除尾部URL,但我可以为这些目录添加一个忽略规则。

干杯

回答

13

让下面.htaccess文件的变化

RewriteEngine on 
RewriteBase/

#existing rule 
#remove the www. 
RewriteCond %{HTTP_HOST} ^www.website.co.uk$ [NC] 
RewriteRule ^(.*)$ http://local.website.co.uk/$1 [R=301,L] 

#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] 

# rest of your existing rules go here 
+0

完美的感谢! – AJFMEDIA 2012-01-05 15:36:35