2013-10-18 68 views
2

我有以下網址:.htaccess - 如何從網址中刪除重複的字符?

example.com/hellllllllllo 

而且我一直在尋找一種方式,以避免重複字符高達一倍。

受此問題啓發Remove Characters from URL with htaccess我創建了以下htaccess文檔以避免重複字符。如果這個角色重複了23次以上,那麼url並沒有完全重新編碼,我想知道是否有任何可能的改進?

RewriteCond %{REQUEST_METHOD} !=POST 
RewriteCond %{REQUEST_URI} ^(.*)l{3,}(.*)$ 
RewriteRule . %1ll%2 [R=301,L] 
+0

使用懶惰匹配:'^(。*?)l {3,}(。*)$' – hjpotter92

+0

這是我正在做的事情,但令人驚訝的是它只限於23個字符 – RafaSashi

+1

您正在使用貪婪匹配' )',懶惰匹配是:'(。*?)' – hjpotter92

回答

3

這裏是我完整的答案,以避免在使用懶惰匹配的網址重複的字符在以前的評論samurai8的建議:

重複SLASHS和破折號

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] 

反覆字母詞彙

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] 
. 
. 
. 
相關問題