将www.subdomain.example.com重定向到subdomain.example.com

tes*_*ter 8 apache dns .htaccess

我有一些用户尝试使用www.subdomain.example.com访问注册为subdomain.example.com的网站.

是否有某种.htaccess规则我可以​​添加到将使用www.subdomain.example.com到达的人重定向到subdomain.example.com?

另外,我是否必须更改DNS内容?

Gre*_*ill 16

当然,使用如下指令:

<VirtualHost *:80> 
    ServerName www.subdomain.example.com 
    Redirect permanent / http://subdomain.example.com/ 
</VirtualHost> 
Run Code Online (Sandbox Code Playgroud)

/在使用Redirect指令的时候,Apache会自动保留任何内容,这是一个常见的错误概念,说明为什么这个方法不起作用(事实上它确实如此).

此外,是的,您需要更改DNS记录,因为它www.subdomain.example.com是一个独特的主机名,需要自己的A(或CNAME)记录才能将浏览器指向适当的服务器.