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

2023-09-02 09:49:15 作者:明人不放暗屁

我已经有一些用户试图访问被注册为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> 

阿帕奇自动preserves后,任何事物的 / 使用重定向指令,这是一种常见的误解时,为什么这种方法是不行的(而实际上它)。

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.