DNS将domain.com重定向到www.domain.com [英] DNS redirect domain.com to www.domain.com

查看:64
本文介绍了DNS将domain.com重定向到www.domain.com的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经对该问题进行了网络搜索,但对结果完全失望.这种情况是将对domain.com的所有请求重定向到子域www.domain.com.

I have performed a web search for the question but totally disappointed with the results. The case is to redirect all requests to domain.com to subdomain www.domain.com.

那我有什么:

  1. www.domain.com -主网站域,所有客户请求均应为重定向到这里
  2. domain.com -的另一个网站入口点不使用www前缀的用户,所有请求都应重定向到www.domain.com
  3. mydomain.com -备用网站别名,全部请求应重定向到www.domain.com
  4. www.mydomain.com -对于使用www前缀的用户,所有请求都应重定向到www.domain.com
  1. www.domain.com - main website domain, all client requests should be redirected here
  2. domain.com - another website entry point for people not using www prefix, all requests should be redirected to www.domain.com
  3. mydomain.com - alternative website alias, all requests should be redirected to www.domain.com
  4. www.mydomain.com - for people using www prefix, all requests should be redirected to www.domain.com

我知道可以使用.htaccess和PHP来实现.但是我想弄清楚如何仅使用DNS就能做到这一点.我也知道DNS查询的结果不会改变HTTP层中发生的情况,因此最初输入的域名将始终是发送到主机中Web服务器的域名.因此,要将domain.com重写为www.domain.com,我仍然需要Apache mod_rewrite.但是我想做DNS的主要工作(CNAME和A记录).

I understand this is possible using .htaccess and PHP. But I want to figure out how this can be done using DNS only. I also understand that the result of the DNS query doesn't change what happens in the HTTP layer so the originally entered domain name will always be the one that's sent to the web server in the Host. So to rewrite domain.com to www.domain.com I will still need Apache mod_rewrite. But I want to do main part of work with DNS (CNAME and A records).

所以主要问题是上述每个域应具有哪些CNAME和A记录?

So the main question is what CNAME and A records each domain above should have?

推荐答案

您可以将www.domain.com设置为A记录,并将www.domain.com的所有其他域名设置为CNAME.但这只能解决",如果www.domain.com的IP地址发生更改,您不必更改其他DNS实体,因为它们是别名.

You could make www.domain.com the A record and all the other domainnames CNAMEs of www.domain.com. But this only "solves" that if the IP address of www.domain.com changes you don't have to alter the other DNS enties as they are aliases.

因此,在DNS级别上,无法执行重定向.这是有充分的理由的,因为DNS仅用于HTTP.例如,如果所有对domain.com的请求都将重定向到www.domain.com,则您的电子邮件地址将更改为user@www.domain.com.

So on the DNS level there is no way to enforce a redirect. And for a good reason because DNS is used for more then only HTTP. For example if all request for domain.com would redirect to www.domain.com your email addresses will change to user@www.domain.com.

因此,对于HTTP重定向,您将必须使用HTTP解决方案.这可以在网络服务器级别(mod_rewrite,代码,javascript(ugh)等).但是您也可以在网络服务器前面安装一个代理来处理此问题.

So for HTTP redirection you will have to use an HTTP solution. This can be at the webserver level (mod_rewrite, in code, javascript (ugh), etc..) but you could also have a proxy in front of your webserver to handle this.

这篇关于DNS将domain.com重定向到www.domain.com的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆