我有以下重写规则,以控制我的不同国际域名重定向到主域。
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。
有什么我能做的吗?
谢谢!
发布于 2013-07-11 03:22:22
模式匹配有几个问题,但问题可能出在与国际TLD匹配的行中。下面是每一行的问题:
.是一个通配符,因此您将在www.domain.com上获得负匹配,但也会使用*匹配0个或多个任何字符。%{HTTP_HOST}永远不应为空。.是任何字符的通配符,您不能将%{HTTP_HOST}的结尾与$完全匹配。使用a ?使第一个模式变得不贪婪。您不需要在co.in上进行匹配,因为它将通过in.[percent]实际上是%,这正是它应该是的。尝试以下操作来代替您现在所拥有的:
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/进行测试
重写:
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无重写:
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发布于 2013-07-11 17:28:35
谢谢!这让我找到了解决这个问题的正确方向。这就是我用来让它工作的东西。
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]https://stackoverflow.com/questions/17577088
复制相似问题