首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >RewriteCond导致别名重定向到.in域

RewriteCond导致别名重定向到.in域
EN

Stack Overflow用户
提问于 2013-07-11 01:26:56
回答 2查看 232关注 0票数 0

我有以下重写规则,以控制我的不同国际域名重定向到主域。

代码语言:javascript
复制
RewriteCond %{HTTP_HOST} !^www..*
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} ^([^.]*).(ru|co.in|in|de|com.br|co.uk|ca|com|com/)
RewriteRule ^.*$ http://www.[percent]1.[percent]2[percent]{REQUEST_URI} [R=301,L]

这在过去的几年里一直很有效。

现在,当我尝试创建一个包含上述字母之一的域别名时,例如: tvonline.domain.com,它会重定向到tvon.in。基本上发生在任何包含字母的别名中,ru,de,ca。

有什么我能做的吗?

谢谢!

EN

回答 2

Stack Overflow用户

发布于 2013-07-11 03:22:22

模式匹配有几个问题,但问题可能出在与国际TLD匹配的行中。下面是每一行的问题:

  1. .是一个通配符,因此您将在www.domain.com上获得负匹配,但也会使用*匹配0个或多个任何字符。
  2. %{HTTP_HOST}永远不应为空。
  3. .是任何字符的通配符,您不能将%{HTTP_HOST}的结尾与$完全匹配。使用a ?使第一个模式变得不贪婪。您不需要在co.in上进行匹配,因为它将通过in.
  4. I'm猜测来匹配,即您示例中的[percent]实际上是%,这正是它应该是的。

尝试以下操作来代替您现在所拥有的:

代码语言:javascript
复制
RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTP_HOST} ^(.*?)\.(ru|in|de|com\.br|co\.uk|ca|com|com)$
RewriteRule ^.*$ http://www.%1.%2%{REQUEST_URI} [R=301,L]

使用http://htaccess.madewithlove.be/进行测试

重写:

代码语言:javascript
复制
Input URL: http://tvonline.domain.com/test.html

1. RewriteCond %{HTTP_HOST} !^www\. 
     This condition was met
2. RewriteCond %{HTTP_HOST} ^(.*?)\.(ru|in|de|com\.br|co\.uk|ca|com|com)$   
     This condition was met
3. RewriteRule ^.*$ http://www.%1.%2%{REQUEST_URI} [R=301,L]    
     This rule was met, the new url is http://www.tvonline.domain.com/test.html
     The tests are stopped, using a different host will cause a redirect

Output URL: http://www.tvonline.domain.com/test.html

无重写:

代码语言:javascript
复制
Input URL: http://www.tvonline.domain.com/test.html

1. RewriteCond %{HTTP_HOST} !^www\. 
     This condition was not met
2. RewriteCond %{HTTP_HOST} ^(.*?)\.(ru|in|de|com\.br|co\.uk|ca|com|com)$   
     This condition was met
3. RewriteRule ^.*$ http://www.%1.%2%{REQUEST_URI} [R=301,L]    
     This rule was not met because one of the conditions was not met
票数 2
EN

Stack Overflow用户

发布于 2013-07-11 17:28:35

谢谢!这让我找到了解决这个问题的正确方向。这就是我用来让它工作的东西。

代码语言:javascript
复制
RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTP_HOST} ^([^.]*?).(ru|in|de|com\.br|co\.uk|ca|com|com)$
RewriteRule ^.*$ http://www.%1.%2%{REQUEST_URI} [R=301,L]
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17577088

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档