规则不将 .co.uk 重定向到 .com
我一直在尝试让我的网站在访问者访问 .co.uk 时自动重定向到 .com。如果他们访问domain.com,也会被带到www.domain.com,
我的httpd.conf 中有下面的代码。它似乎可以使用 domain.com
到 www.domain.com
,但不能使用 domain.co.uk
或 www.domain .co.uk 至
www.domain.com
RewriteEngine on
RewriteBase /
RewriteCond %{http_host} ^domain.com [NC,OR]
RewriteCond %{http_host} ^domain.co.uk [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,NC]
I have been trying to get my site, when a visitor goes to .co.uk to be automatically redirected to .com. As well as if they go to domain.com to be taken to www.domain.com
I have the code below in my httpd.conf. It appears to be working with domain.com
to www.domain.com
but not domain.co.uk
or www.domain.co.uk
to www.domain.com
RewriteEngine on
RewriteBase /
RewriteCond %{http_host} ^domain.com [NC,OR]
RewriteCond %{http_host} ^domain.co.uk [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,NC]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您的重写规则位于 htaccess 文件中,那么这应该可以工作。如果它们位于 vhost 文件(或 Apache httpd.conf 本身)中,请尝试删除
/
。并尝试始终区分大小写(要习惯,因为大多数语言都区分大小写,这是一个好习惯):
如果在
.htaccess
中:如果在
vhost
中或httpd.conf
文件:请尝试使用
RewriteLog
指令:它可以帮助您追踪此类问题:告诉我它是否有效。
If your rewrite rules are in an htaccess file, this should work. If they are in a vhost file (or the Apache httpd.conf itself) try to remove the
/
.And try to always be case sensitive (get used to because most of languages are case sensitive it's a good habit to take):
If in a
.htaccess
:If in a
vhost
orhttpd.conf
file:And please try to use the
RewriteLog
directive: it helps you to track down such problems:Tell me if it works.
HTTP_HOST 的名称区分大小写吗? RewriteCond 文档始终将其列为 HTTP_HOST,而不是 http_host。 NC 标志对此没有帮助,因为它适用于字符串值,而不是变量名称。
Is the name of HTTP_HOST case-sensitive? The RewriteCond documentation always lists it as HTTP_HOST, not http_host. The NC flag won't help with that, since it applies to the string values, not variable names.