简体   繁体   中英

Remove forward slashes from url by htaccess

Trying to remove double slashes after domain. The following mod_rewrite expressions seem to work for URLs such as http://example.com//login , but do not work for domain//

RewriteCond %{HTTP_HOST} !=""
RewriteCond %{THE_REQUEST} ^[A-Z]+\s//+(.*)\sHTTP/[0-9.]+$ [OR]
RewriteCond %{THE_REQUEST} ^[A-Z]+\s(.*/)/+\sHTTP/[0-9.]+$
RewriteRule .* http://%{HTTP_HOST}/%1 [R=301,L]

I want to convert URL from :

 http://example.com//login

To

 http://example.com/login

Would you please give me proper suggestion about how to remove double slashes from url?

Any kind of help would be highly appreciated.

Thanks in advance.

Try :

RewriteEngine on

RewriteRule ^/+(.*)$ /$1 [L,R]

You can also use RedirectMatch

RedirectMatch ^//+(.*)$ /$1

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM