我有以下网址:
example.com/hellllllllllo
Run Code Online (Sandbox Code Playgroud)
我正在寻找一种方法来避免重复的字符增加一倍.
灵感来自这个问题/答案使用htaccess从URL中删除字符我创建了以下htaccess文档以避免重复的字符.如果角色重复超过23次,则网址没有完全重写,我想知道是否有任何可能的改进?
RewriteCond %{REQUEST_METHOD} !=POST
RewriteCond %{REQUEST_URI} ^(.*)l{3,}(.*)$
RewriteRule . %1ll%2 [R=301,L]
Run Code Online (Sandbox Code Playgroud) 我目前有一个网站,客人可以使用任意数量的斜杠访问每个网址,以分隔文件夹名称.例如,如果URL应该是:
http://example.com/one/two/three/four
Run Code Online (Sandbox Code Playgroud)
然后,用户可以通过以下任何一种方式访问同一页面:
http://example.com/one//two///three////four/////
http://example.com/one/two////three/four/////
http://example.com///one///////////two////three/four/
http://example.com///////////one///////////two/three/four
Run Code Online (Sandbox Code Playgroud)
但是,我希望上面的示例网址仅将用户重定向到此网址:
http://example.com/one/two/three/four
Run Code Online (Sandbox Code Playgroud)
这是我的.htaccess文件,试图阻止巨大的斜杠:
RewriteCond %{ENV:REDIRECT_STATUS} !^$
RewriteRule .* - [L]
RewriteRule ^(.*)/+$ /$1 [R=301,L,NC]
RewriteCond %{REQUEST_URI} ^/+(.*)/+$
RewriteRule .* /%1 [R=301,L]
Run Code Online (Sandbox Code Playgroud)
第三行成功停止长URL的尾部斜杠.第4行和第5行是我尝试在域名后立即停止斜杠,但这是不成功的.
我问这个问题的原因是因为我不希望谷歌抓住我的重复内容,并且在网站上有活跃的adsense,谷歌可能会扫描我访问的所有网址.
有没有RewriteCond/RewriteRule组合我可以用来剥去中间斜线或者它更复杂?