htaccess的 - 如何从URL删除重复字符? [英] .htaccess - how to remove repeated characters from url?

查看:156
本文介绍了htaccess的 - 如何从URL删除重复字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下网址:

  example.com/hellllllllllo
 

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

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

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

解决方案

下面是我完整的答案,以避免在使用懒惰匹配的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]
.
.
.

这篇关于htaccess的 - 如何从URL删除重复字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆