将 www.subdomain.example.com 重定向到 subdomain.example.com [英] redirecting www.subdomain.example.com to subdomain.example.com
问题描述
我有一些用户试图访问注册为 subdomain.example.com 和 www.subdomain.example.com 的网站.
I've had some users trying to access a site that is registered as subdomain.example.com with www.subdomain.example.com.
是否可以添加某种 .htaccess 规则来将使用 www.subdomain.example.com 到达的人重定向到 subdomain.example.com?
is there some sort of .htaccess rule I can add to redirect people that arrive using www.subdomain.example.com to subdomain.example.com?
另外,我需要更改 DNS 内容吗?
Also, do I have to change DNS stuff?
推荐答案
当然,使用如下指令:
<VirtualHost *:80>
ServerName www.subdomain.example.com
Redirect permanent / http://subdomain.example.com/
</VirtualHost>
Apache 在使用 Redirect
指令时会自动保留 /
之后的任何内容,这是关于为什么此方法不起作用的常见误解(实际上它确实起作用).
Apache automatically preserves anything after the /
when using the Redirect
directive, which is a common misconception about why this method won't work (when in fact it does).
此外,是的,您需要更改 DNS 记录,因为 www.subdomain.example.com
是一个独特的主机名,需要自己的 A(或 CNAME)记录来将浏览器指向适当的首先是服务器.
Also, yes you will need to change DNS records, because www.subdomain.example.com
is a distinct hostname that needs its own A (or CNAME) record to point the browser to an appropriate server in the first place.
这篇关于将 www.subdomain.example.com 重定向到 subdomain.example.com的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!