【发布时间】:2016-06-18 09:52:41
【问题描述】:
我已经尝试解决这个问题几个小时了,但无济于事。言归正传,我拥有具有不同 TLD、.com 和 .co.uk 的相同域。这是我目前的 htaccess 文件:
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 例如:
- www.example.com
- http://www.example.com
- https://example.com
任何人都可以看到我在哪里出错了吗?我对 htaccess 重定向不是很有经验,因此不胜感激。
【问题讨论】:
标签: apache .htaccess redirect mod-rewrite