.htaccess 删除url末尾的尾随斜杠

.htaccess 删除url末尾的尾随斜杠,.htaccess,redirect,.htaccess,Redirect,我知道有很多关于这个题目的问题,我都试过了。我想做的是重定向 localhost/site/tours/picnics/ 到 但是我试过的每一个代码(比如这一个) 出于某种原因,将我重定向到localhost/野餐。我不明白为什么会这样。我甚至尝试过重写base/site/,但没有任何区别。有人能指出这段代码中的问题吗 编辑:这是我完整的htaccess文件 RewriteEngine On #RewriteBase /site/ RewriteRule ^destinations/(.*)$

我知道有很多关于这个题目的问题,我都试过了。我想做的是重定向

localhost/site/tours/picnics/

但是我试过的每一个代码(比如这一个)

出于某种原因,将我重定向到
localhost/野餐
。我不明白为什么会这样。我甚至尝试过重写base/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
是从具有原始和完整请求URL的
{u请求}
中捕获的。

在localhost/site/中,确保将此规则保持在
RewriteBase
行的正下方它可以工作,但它会在
localhost
之后继续添加一个/,也就是说,每次我转到链接
localhost/site/tours/bunch/
时,它就会变成
localhost//site/tours/bunch
,再次转到
localhost////site/tours/bunch/
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]