通过 .htaccess 从 URL 中删除双斜线或更多斜线的问题 [英] Issue In Removing Double Or More Slashes From URL By .htaccess
问题描述
我正在使用以下 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]
这适用于 uri 中间出现的斜线,例如,如果使用 url:
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
但是如果 url 在开头包含双斜杠,就在域名之后,那么它就不起作用,例如:
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
它没有被重定向.
我如何修复上述规则以适用于此类网址?谢谢.
How I can fix the above rule to work for this type of urls as well? Thanks.
推荐答案
试试看:
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]
这篇关于通过 .htaccess 从 URL 中删除双斜线或更多斜线的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!