如何通过DNS记录路由/重定向* .foo.org→* .foo.biz? [英] How to route/redirect *.foo.org → *.foo.biz via DNS records?

查看:65
本文介绍了如何通过DNS记录路由/重定向* .foo.org→* .foo.biz?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注册了我的域名 foo.org ,他们免费为我提供了 foo.biz .我不是很喜欢,但是正如我所说,他们免费提供给我...而且我想将涉及 foo.biz 的每个请求绝对路由到 foo.com ,包括子域.

I registered my domain foo.org and along with it they gave me foo.biz for free. I don't really like it, but as I said, they gave it to me for free... And I want to route absolutely every request involving foo.biz to foo.com, including subdomains.

foo.org 的DNS配置中,我设置了 @ www 以及通配符子域 *作为 A 记录到我的主机的IP地址

In the DNS configuration of foo.org, I set up @ and www, as well as the wildcard subdomain * as A records to my host's IP address,

对于 foo.biz 的DNS配置,我正在考虑使用301重定向,但它们不能与通配符子域配合使用,或者至少我不知道如何实现自动映射我想要的是,即不必手动为每个子域进行操作,也可以在没有通配符的情况下使用.

For the DNS configuration of foo.biz, I was thinking of using 301 redirects but they don't play well with wildcard subdomains, or at least I have no idea how to achieve the automatic mapping I want, i.e., without having to do it manually for each subdomain and not use without the wildcard.

由于我真的想将 foo.org 命名为标准名称并使用 foo.biz 作为廉价别名,因此诉诸CNAME记录是很有意义的,但是我该怎么做才能实现映射?

Since I really want to make foo.org the canonical name and have foo.biz just as a cheap alias, it makes sense to resort to CNAME records, but how can I do that in order to achieve the mapping???

非常感谢您提供的知识丰富的建议!

I'd appreciate your most educated advice!

推荐答案

您不能仅通过使用DNS来做到这一点.当然,您可以将 *.foo.biz 的CNAME记录设置为 foo.org ,但这不会使浏览器在以下情况下请求 foo.org 用户在浏览器的地址栏中输入 foo.biz .您必须在HTTP服务器级别上使用重定向才能实现此目的.

You can't do this by simply using DNS. Sure you can setup a CNAME record for *.foo.biz to foo.org but that won't make browsers request foo.org when a user types foo.biz in her browser's address bar. You have to use redirects on the HTTP server level to achieve this.

为清楚起见,让我们看一下stackoverflow.com的DNS设置:

To make myself clear, let's have a look at the DNS setup of stackoverflow.com:

~# dig www.stackoverflow.com
;; QUESTION SECTION:
;www.stackoverflow.com.         IN     A

;; ANSWER SECTION:
www.stackoverflow.com.   300    IN     CNAME   stackoverflow.com
stackoverflow.com.       24     IN     A       192.252.206.16

我们可以看到,stackoverflow.com是www.stackoverflow.com的规范名称.但是,如果我在浏览器的地址栏中键入 www.stackoverflow.com ,它将向192.252.206.16发送以下请求:

As we can see, stackoverflow.com is the canonical name of www.stackoverflow.com. But still, if I type www.stackoverflow.com in my browser's address bar, it will send the following request to 192.252.206.16:

GET / HTTP/1.1
Host: www.stackoverflow.com
Connection: keep-alive
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
User-Agent: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.66 Safari/537.36
Accept-Encoding: gzip,deflate,sdch
Accept-Language: de-DE,de;q=0.8,en-US;q=0.6,en;q=0.4

这里有趣的一点是,Chrome浏览器可能已经查看了StackOverflow的DNS配置,并且可能已经看到 stackoverflow.com 是该服务器的规范名称,但是它仍然发送了 www.stackoverflow.com Host 标头字段中.这样一来,管理员可以在一台物理计算机上托管多个站点(基于名称的虚拟托管).

The interesting bit here is that Chrome may have looked at StackOverflow's DNS configuration and may have seen that stackoverflow.com is that server's canonical name, but it still sent www.stackoverflow.com in the Host header field. This allows administrators to host multiple sites on one physical machine (name-based virtual hosting).

但是,位于192.252.206.16的服务器通过以下方式响应我的请求

However, the server at 192.252.206.16 responds to my request with

HTTP/1.1 301 Moved Permanently
Content-Type: text/html; charset=UTF-8
Location: http://stackoverflow.com/
Date: Mon, 16 Sep 2013 11:00:43 GMT
Content-Length: 148

<head><title>Document Moved</title></head>
<body><h1>Object Moved</h1>This document may be found <a HREF="http://stackoverflow.com/">here</a></body>

,因此将我重定向到stackoverflow.com.

and thus redirects me to stackoverflow.com.

为了实现映射,您需要在HTTP服务器配置中添加一些重写规则.对于Apache,这可能是这样的:

In order to achieve your mapping, you need to add some rewrite rules in your HTTP server configuration. For Apache this could look like this:

<VirtualHost *:80>
    ServerName foo.biz
    ServerAlias *.foo.biz

    RewriteEngine On

    RewriteCond %{HTTP_HOST} =foo.biz
    RewriteRule ^(.*)$ http://foo.org$1 [L,R=301]

    RewriteCond %{HTTP_HOST} ^(.*).foo.biz$
    RewriteRule ^(.*)$ http://%1.foo.org$1 [L,R=301]
</VirtualHost>

这会将 foo.biz/bar 重写为 foo.org/bar ,并将 anything.foo.biz/something 重写为everything.foo.org/something .不过,您仍然需要foo.biz的DNS条目和foo.org网站的网站配置.

This will rewrite foo.biz/bar to foo.org/bar and anything.foo.biz/something to anything.foo.org/something. You still need the DNS entries for foo.biz and the site configurations for the foo.org sites, though.

希望有帮助...

这篇关于如何通过DNS记录路由/重定向* .foo.org→* .foo.biz?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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