在url结尾处删除尾部斜杠
问题描述:
我知道这个标题有一个巴吉尔数量的问题,我已经尝试过。我想要做的是重定向在url结尾处删除尾部斜杠
localhost/site/tours/picnics/
到
localhost/site/tours/picnics
但每次我试图代码,(这一个实例)
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{THE_REQUEST} \s(.+?)/+[?\s]
RewriteRule ^(.+?)/$ /$1 [R=301,L]
重定向我localhost/picnics
为一些原因。我不明白为什么会发生。我甚至试过RewriteBase /site/
但它没有任何区别。有人可以指出这个代码中的问题吗?
编辑:这里是我的完整htaccess文件
RewriteEngine On
#RewriteBase /site/
RewriteRule ^destinations/(.*)$ destinations.php?destId=$1 [NC,L]
#RewriteRule ^tours/? tour-listing.php [NC,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{THE_REQUEST} \s(.+?)/+[?\s]
RewriteRule ^(.+?)/$ /$1 [R=301,L]
RewriteRule ^tours/?(.*)$ tour-listing.php?cat=$1 [NC,L]
RewriteRule ^tour/([0-9a-zA-Z]+)$ tour.php?id=$1 [NC,L]
RewriteRule ^hotel/([0-9a-zA-Z]+)$ hotel-details.php?id=$1 [NC,L]
答
您的规则改成这样:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{THE_REQUEST} \s/+(.+?)/+[?\s]
RewriteRule /$ /%1 [R=301,L,NE]
$1
相对值捕捉到只,但%1
正在从%{THE_REQUEST}
捕捉你的当前目录有原始和完整的请求URL。
在localhost/site/ – VeeK