0

我如何仅从 .in 或 .net 和其他人重定向到 .com。这是我尝试过的

RewriteEngine on 
Rewritecond %{HTTP_HOST} !^www\.mysite\.com
RewriteRule ^(.*)$ http://www.mysite.com/$1 [R=301,L]

我如何使它也适用于子域?例子:

http://subdomain.mysite.in/app/rest-of-the-url
http://subdomain.mysite.net/app/rest-of-the-url

应该去

http://subdomain.mysite.com/app/rest-of-the-url
4

3 回答 3

0
RewriteEngine on

Rewritecond %{HTTP_HOST} !^(www\.)?mysite\.com$ [NC]
Rewritecond %{HTTP_HOST} ^(.+\.)?mysite\.(?!com).+$ [NC]
RewriteRule ^(.*)$ http://%1mysite.com/$1 [R=301,L]

this is working fine except in one case

https://www.mysite.net/app/xyz is not getting redirected to https://www.mysite.com/app/xyz

于 2013-08-21T12:38:38.847 回答
0
RewriteEngine on

Rewritecond %{HTTP_HOST} !^(www\.)?mysite\.com$ [NC]
Rewritecond %{HTTP_HOST} ^(.+\.)?mysite\.(?!com).+$ [NC]
RewriteRule ^(.*)$ http://%1mysite.com/$1 [R=301,L]
于 2013-08-21T11:54:02.493 回答
0

您没有理由将这些组合成一条规则。您应该处理主域,没有“www”,然后分别处理具有不同 TLD 的子域。

RewriteEngine on 
RewriteCond %{HTTP_HOST} ^mysite\.com$ [NC]
RewriteRule ^(.*)$ http://www.mysite.com/$1 [R=301,L]

RewriteCond %{HTTP_HOST} ^subdomain\.mysite\.([^.]+)$ [NC]
RewriteCond %1 !com
RewriteRule ^(.*)$ http://subdomain.mysite.com/$1 [R=301,L]
于 2013-08-21T12:47:23.743 回答