htaccess的 - 有连接codeD重音字符域名,删除多个斜杠 [英] htaccess - Remove multiple slashes after domain with encoded accented characters

查看:145
本文介绍了htaccess的 - 有连接codeD重音字符域名,删除多个斜杠的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以在任何地方使用删除多个斜线的网址:

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

不过,这并不域后多次斜线工作

我曾尝试

 的RewriteCond%{HTTP_HOST}!=
的RewriteCond%{} THE_REQUEST ^ [A-Z] + \\ S + //(*)\\ SHTTP / [0-9] + $ [OR]
的RewriteCond%{} THE_REQUEST ^ [A-Z] + \\ S(。* /)/ + \\ SHTTP / [0-9] + $
。*重写规则的http://%{HTTP_HOST} /%1 [R = 301,L]


  • 从:<一href=\"http://stackoverflow.com/questions/2846225/remove-multiple-trailing-slashes-mod-rewrite\">remove多个尾随斜线mod_rewrite的

 的RewriteCond%{} THE_REQUEST ^([A-Z] {3,9})\\(。*)//([^ \\] *)
重写规则^ 2%/ 3%[R = 301,L]


  • 从:
  • 删除后斜线

去当两个产生预期rewirting

  domain.com /////你好

  domain.com/hello

 domain.com/////héllo

结果是EN codeD

  domain.com/h%25c%25allo

如何prevent重音字符域名,删除多个斜线时获得EN codeD?

编辑:梨anubhava的答案

 的RewriteCond%{THE_REQUEST} \\ S / +(。*?)/ {2}([^ \\ S] *)[NC]
重写规则^%1 /%2 [R = 301,L,NE]

重音字符被保护,trimed与更迭超过反复斜线

  domain.com //////// HELLO

,但不与只有2

 domain.com//héllo


解决方案

这规则应该为你工作:

  RewriteEngine叙述在
的RewriteBase /的RewriteCond%{} THE_REQUEST ^ [A-Z] {3} \\ S / +(。*?)/ +(/ [^ \\ S] +)[NC]
重写规则^%1%2 [R = 302,L,NE]

这将做这些重定向:


  1. /////帮助=&GT; /帮助

  2. /////你好///// ABC ///// 123 =&GT; / HELLO / ABC / 123

I can remove multiple slashes anywhere in URL using:

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

But it doesn't work for multiple slashes after the domain

I have tried

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

and

RewriteCond %{THE_REQUEST} ^([A-Z]{3,9})\ (.*)//([^\ ]*)
RewriteRule ^ %2/%3 [R=301,L]

both produce the expected rewirting when going from

domain.com/////hello

to

domain.com/hello

but from

 domain.com/////héllo

the result is encoded

domain.com/h%25c%25allo

How to prevent accented characters to get encoded when removing multiple slashes after domain ?

EDIT: pear to anubhava's answer

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

The accented character is protected and trimed with succes with more than to repeated slashes

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

but not with only 2

domain.com//héllo

解决方案

This rule should work for you:

RewriteEngine On
RewriteBase /

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

This will do these redirections:

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

这篇关于htaccess的 - 有连接codeD重音字符域名,删除多个斜杠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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