由网友(搁浅的心碎)分享简介:我有以下重写规则:#remove the www.RewriteCond %{HTTP_HOST} ^www.website.co.uk$ [NC]RewriteRule ^(.*)$ http://local.website.co.uk/$1 [R=301,L]#this removes php extenti...
我有以下重写规则:
#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]
我想在删除了结尾的斜线规则添加,如果有人试图访问一个网站。
I want to add in a rule that removes the trailing slash if someone tries to access site with one.
例如
website.co.uk/cheese/应该重定向到/奶酪
website.co.uk/cheese/ should redirect to /cheese
你可以看到我有一个重定向输尿管镜气压弹道碎石和.php延伸的规则,不知道从哪里开始。
as you can see I have a rule that redirects ursl with the .php extention, not sure where to begin.
我确实有我不希望删除尾随URL的根文件夹目录,但我可以添加一个无视规则的。
I do have directory in the root folder which I do not wish to remove the trailing url, but I can add a ignore rule for those.
干杯
推荐答案
请在下面给你的.htaccess文件的变化
Make the change below to your .htaccess file
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
相关推荐
最新文章