[英]how to remove slash from url with htaccess
how to redirect trailing slash from URL i want remove slash from end and romove slash between FILENAME 如何从URL重定向尾部斜杠我想从结尾删除斜杠并在FILENAME之间移动斜杠
url => http://localhost/
url => http://localhost/customer/
url => http://localhost/customer/account///login/
url => http://localhost/customer/account/login///register///
And after cleaning url 并清理URL后
http://localhost
http://localhost/customer
http://localhost/customer/account/login
http://localhost/customer/account/login/register
this is code htaccess 这是代码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]
RewriteRule htaccess to always remove trailing slash even directory RewriteRule htaccess始终删除斜杠偶数目录
Try To Use The Code Below - 尝试使用以下代码-
DirectoryIndex index.php
RewriteEngine On
# remove trailing slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{THE_REQUEST} \s(.+?)/+[?\s]
RewriteRule ^(.+?)/$ /$1 [R=301,L]
# To internally forward /dir/file to /dir/file.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1.php -f [NC]
RewriteRule ^(.+?)/?$ /$1.php [L]
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]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.