htaccess – 删除编码重音字符的域后的多个斜线

我可以使用以下方法在URL中的任何位置删除多个斜杠:

RewriteCond %{REQUEST_URI} ^(.*?)(/{2,})(.*)$ RewriteRule . %1/%3 [R=301,L] 

但是它不适用于域之后的多个斜杠

我努力了

 RewriteCond %{HTTP_HOST} !="" RewriteCond %{THE_REQUEST} ^[AZ]+\s//+(.*)\sHTTP/[0-9.]+$ [OR] RewriteCond %{THE_REQUEST} ^[AZ]+\s(.*/)/+\sHTTP/[0-9.]+$ RewriteRule .* http://%{HTTP_HOST}/%1 [R=301,L] 
  • 从: 删除多个后缀斜线mod_rewrite

 RewriteCond %{THE_REQUEST} ^([AZ]{3,9})\ (.*)//([^\ ]*) RewriteRule ^ %2/%3 [R=301,L] 
  • 从: 删除域后的斜线

从去往时都会产生预期的回缩

 domain.com/////hello 

 domain.com/hello 

但来自

  domain.com/////héllo 

结果被编码

 domain.com/h%25c%25allo 

如何防止重音字符在域之后删除多个斜杠时进行编码?

编辑:梨anubhava的答案

 RewriteCond %{THE_REQUEST} \s/+(.*?)/{2,}([^\s]*) [NC] RewriteRule ^ %1/%2 [R=301,L,NE] 

重音字符被保护和成功与不止重复的斜杠成功

 domain.com////////héllo 

但不是只有2

 domain.com//héllo 

这个规则应该适合你:

 RewriteEngine On RewriteBase / RewriteCond %{THE_REQUEST} ^[AZ]{3,}\s/+(.*?)/+(/[^\s]+) [NC] RewriteRule ^ %1%2 [R=302,L,NE] 

这将做这些重定向:

  1. /////help => /help
  2. /////héllo/////abc/////123 => /héllo/abc/123

anubhava的答案是最短的,但也可以是这个也是工作:

 RewriteCond %{HTTP_HOST} !="" RewriteCond %{THE_REQUEST} ^[AZ]+\s//+(.*)\sHTTP/[0-9.]+$ [OR] RewriteCond %{THE_REQUEST} ^[AZ]+\s(.*/)/+\sHTTP/[0-9.]+$ RewriteRule .* http://%{HTTP_HOST}/%1 [R=301,L,NE]