Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
322 views
in Technique[技术] by (71.8m points)

Issue In Removing Double Or More Slashes From URL By .htaccess

I am using the following htaccess rul to remove double or more slashes from web urls:

#remove double/more slashes in url
RewriteCond %{REQUEST_URI} ^(.*)//(.*)$
RewriteRule . %1/%2 [R=301,L]

This is working fine for slashes occured in the middle of uris, such as, If use url:

http://demo.codesamplez.com/html5//audio

Its being redirected to proper single slahs url:

http://demo.codesamplez.com/html5/audio

But if the url contains double slashes in the beginning, JUST AFTER the domain name, then there its not working, example:

http://demo.codesamplez.com//html5/audio

its not being redirected.

How I can fix the above rule to work for this type of urls as well? Thanks.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Give it a try with:

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}s/{2,} [NC]
RewriteRule ^(.*) $1 [R=301,L]

It should redirect to a single slash at the end of the domain. And an improvement on yours:

RewriteCond %{REQUEST_URI} ^(.*)/{2,}(.*)$
RewriteRule . %1/%2 [R=301,L]

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...