htaccess的 - 如何从URL删除重复字符?字符、htaccess、URL

2023-09-02 00:57:41 作者:溫柔猎殺者

我有以下网址:

  example.com/hellllllllllo
 

和我一直在寻找一种方式,以避免重复字符了一倍。

这个问题启发/答案从URL与htaccess的删除字符我创建了以下htaccess的文件,以避免重复字符。如果字符重复超过23倍的URL不是完全rewrited,我想知道是否有任何可能的改良效果?

 的RewriteCond%{REQUEST_METHOD}!= POST
的RewriteCond%{REQUEST_URI} ^(。*)l {3}(。*)$
重写规则。 %1LL%2 [R = 301,L]
 

解决方案 .htaccess文件如何创建

下面是我完整的答案,以避免在使用懒惰匹配的URL重复的字符在previous意见建议的samurai8:

重复SLASHS和破折号

 的RewriteCond%{REQUEST_METHOD}!= POST
的RewriteCond%{REQUEST_URI} ^(。*?)(/ {2})(。*)$
重写规则。 %1 /%3 [R = 301,L]

的RewriteCond%{REQUEST_METHOD}!= POST
的RewriteCond%{REQUEST_URI} ^(*?)( -  {2})$(*)。
重写规则。 %1%3 [R = 301,L]

的RewriteCond%{REQUEST_METHOD}!= POST
的RewriteCond%{REQUEST_URI} ^(。*?)(_ {2})(。*)$
重写规则。 %1_%3 [R = 301,L]
 

在词屡封

 的RewriteCond%{REQUEST_METHOD}!= POST
的RewriteCond%{REQUEST_URI} ^(。*?)A {3}(。*)$
重写规则。 %1AA%2 [R = 301,L]

的RewriteCond%{REQUEST_METHOD}!= POST
的RewriteCond%{REQUEST_URI} ^(。*?)B {3}(。*)$
重写规则。 %1BB%2 [R = 301,L]

的RewriteCond%{REQUEST_METHOD}!= POST
的RewriteCond%{REQUEST_URI} ^(。*?)C {3}(。*)$
重写规则。 %1毫升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]
.
.
.