如何从URL重定向尾部斜杠我想从末尾删除斜杠并在FILENAME之间删除斜杠
url => http://localhost/
url => http://localhost/customer/
url => http://localhost/customer/account///login/
url => http://localhost/customer/account/login///register///
清理网址后
http://localhost
http://localhost/customer
http://localhost/customer/account/login
http://localhost/customer/account/login/register
这是代码htaccess
RewriteEngine On
RewriteBase /
Options -Indexes
Options -MultiViews
# view only www
# RewriteCond %{HTTP_HOST} !^$
# RewriteCond %{HTTP_HOST} !^www\. [NC]
# RewriteCond %{HTTPS}s ^on(s)|
# RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
<Files ~ '^.ht'>
order allow,deny
deny from all
</Files>
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
# remove one slash
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(.*?)/+(/[^\s]+) [NC]
RewriteRule ^ %1%2 [R=302,L,NE]
RewriteRule ^(.+?)/$ /$1 [R=302,NE,L]
RewriteRule ^(.*)$ /index.php?url=$1 [QSA,L]
答案 0 :(得分:1)
RewriteRule htaccess总是删除尾随斜杠甚至目录
尝试使用下面的代码 -
{{1}}
答案 1 :(得分:0)
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(.*?)/+(/[^\s]+) [NC]
RewriteRule ^ %1%2 [R=302,L,NE]
RewriteRule ^(.+?)/$ /$1 [R=302,NE,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ /index.php?url=$1 [QSA,L]