2016-03-04 200 views
0

我一直试图解决这个问题几个小时,现在无济于事。为了说明问题,我拥有与不同TLD,.com和.co.uk相同的域名。下面是目前我的htaccess文件:htaccess重定向https,www和com到co.uk

RewriteCond %{HTTPS} off 
# First rewrite to HTTPS: 
# Don't put www. here. If it is already there it will be included, if not 
# the subsequent rule will catch it. 
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] 
# Now, rewrite any request to the wrong domain to use www. 
RewriteCond %{HTTP_HOST} !^www\. 
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301] 
# com to co.uk redirect 
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ [NC] 
RewriteRule ^(.*)$ http://www.example.co.uk/$1 [R=301,L] 

我一直试图在这里测试的配置:http://htaccess.mwl.be/但我发现了一些奇怪的结果,如.com域被追加到.co.uk一个。

它也似乎有些规则工作,而另一些则没有。其目的是example.com的所有变化重定向到https://www.example.co.uk例如:

任何人都可以看到我这个去错了?我对htaccess重定向不太熟悉,所以不胜感激。

回答

0

您可以使用以下方法:

RewriteEngine on 

RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ 
RewriteRule^https://www.example.co.uk%{REQUEST_URI} [NE,L,R] 

上面的规则将重定向:

+0

感谢您的回答。问题是,它似乎没有重定向:example.com到https://www.example.co.uk – DeanHyde

+0

请清除浏览器的缓存或尝试使用不同的网络浏览器来测试它。 – starkeen

相关问题