.htaccess - how to remove repeated characters from url?

前端 未结 1 1583
春和景丽
春和景丽 2020-12-21 14:18

I have the following url:

example.com/hellllllllllo

And I was looking for a way to avoid repeated characters up to double.

Inspired

1条回答
  •  無奈伤痛
    2020-12-21 15:12

    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]
    .
    .
    .
    

    0 讨论(0)
提交回复
热议问题