.htaccess - 如何从url中删除重复的字符? [英] .htaccess - how to remove repeated characters from url?
问题描述
我有以下网址:
example.com/hellllllllllo
/ pre>
我正在寻找一种避免重复字符加倍的方法。
受此启发问题/答案使用htaccess从URL中删除字符我创建了以下htaccess文档避免重复字符。如果角色重复超过23次,url不会被完全重写,我想知道是否有任何可能的改进?
RewriteCond%{REQUEST_METHOD}!= POST
RewriteCond%{REQUEST_URI} ^(。*)l {3,}(。*)$
RewriteRule。 %1ll%2 [R = 301,L]
解决方案这是我的完整答案,以避免在以前的评论中由samurai8提出的使用懒惰匹配的URL中的重复字符:
对于重复的SLASHS和DASHES / p>
RewriteCond%{REQUEST_METHOD}!= POST
RewriteCond%{REQUEST_URI} ^(。*?)(/ {2 ,})(。*)$
RewriteRule。 %1 /%3 [R = 301,L]
RewriteCond%{REQUEST_METHOD}!= POST
RewriteCond%{REQUEST_URI} ^(。*?)( - {2,}) (。*)$
RewriteRule。 %1-%3 [R = 301,L]
RewriteCond%{REQUEST_METHOD}!= POST
RewriteCond%{REQUEST_URI} ^(。*?)(_ {2,}) (。*)$
RewriteRule。 %1_%3 [R = 301,L]
为重复的字母strong>
RewriteCond%{REQUEST_METHOD}!= POST
RewriteCond%{REQUEST_URI} ^(。*?)a {3,}(。*)$
RewriteRule。 %1aa%2 [R = 301,L]
RewriteCond%{REQUEST_METHOD}!= POST
RewriteCond%{REQUEST_URI} ^(。*?)b {3,} )$
RewriteRule。 %1bb%2 [R = 301,L]
RewriteCond%{REQUEST_METHOD}!= POST
RewriteCond%{REQUEST_URI} ^(。*?)c {3,} )$
RewriteRule。 %1cc%2 [R = 301,L]
。
。
。
I have the following url:
example.com/hellllllllllo
And I was looking for a way to avoid repeated characters up to double.
Inspired by this question/answers Remove Characters from URL with htaccess I have created the following htaccess document to avoid repeated characters. If the character is repeated more than 23 times the url is not completely rewrited and I was wondering if there is any possible improvment?
RewriteCond %{REQUEST_METHOD} !=POST RewriteCond %{REQUEST_URI} ^(.*)l{3,}(.*)$ RewriteRule . %1ll%2 [R=301,L]
解决方案Here is my full answer to avoid repeated characters in urls using lazy match as suggested by samurai8 in previous comments:
FOR REPEATED SLASHS AND DASHES
RewriteCond %{REQUEST_METHOD} !=POST RewriteCond %{REQUEST_URI} ^(.*?)(/{2,})(.*)$ RewriteRule . %1/%3 [R=301,L] RewriteCond %{REQUEST_METHOD} !=POST RewriteCond %{REQUEST_URI} ^(.*?)(-{2,})(.*)$ RewriteRule . %1-%3 [R=301,L] RewriteCond %{REQUEST_METHOD} !=POST RewriteCond %{REQUEST_URI} ^(.*?)(_{2,})(.*)$ RewriteRule . %1_%3 [R=301,L]
FOR REPEATED LETTERS IN WORDS
RewriteCond %{REQUEST_METHOD} !=POST RewriteCond %{REQUEST_URI} ^(.*?)a{3,}(.*)$ RewriteRule . %1aa%2 [R=301,L] RewriteCond %{REQUEST_METHOD} !=POST RewriteCond %{REQUEST_URI} ^(.*?)b{3,}(.*)$ RewriteRule . %1bb%2 [R=301,L] RewriteCond %{REQUEST_METHOD} !=POST RewriteCond %{REQUEST_URI} ^(.*?)c{3,}(.*)$ RewriteRule . %1cc%2 [R=301,L] . . .
这篇关于.htaccess - 如何从url中删除重复的字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!