模式匹配存在几个问题,但问题可能出在与您的国际 TLD 匹配的行中。这是每一行的问题:
- The
.
是一个通配符,所以你会得到一个否定匹配,www.domain.com
但也wwwxxx.domain.com
可以*
匹配 0 个或多个任何字符。
%{HTTP_HOST}
永远不应该是空的。
- The
.
是任何字符的通配符,并且您并不完全匹配 with 的%{HTTP_HOST}
结尾$
。使用 a?
使第一个模式变得不贪婪。您不需要匹配 onco.in
因为它将匹配in
.
- 我猜你的例子中的 the
[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