如何使用 A 或 CNAME 记录将 siteA 重定向到 siteB

发布于 2024-07-04 07:35:20 字数 1476 浏览 4 评论 0 原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

执笔绘流年 2024-07-11 07:35:20

您可以通过多种非 DNS 方式来执行此操作。 subdomain.hostone.com 的登陆页面可以有 HTTP 重定向。 hostone.com 的网络服务器可以配置为重定向(在 Apache 中很容易,不确定 IIS)等。

You can do this a number of non-DNS ways. The landing page at subdomain.hostone.com can have an HTTP redirect. The webserver at hostone.com can be configured to redirect (easy in Apache, not sure about IIS), etc.

拍不死你 2024-07-11 07:35:20

您只能将 DNS 名称绑定到不同的 IP 地址,因此,如果您使用的是虚拟主机,则通过 DNS 进行重定向将不起作用。

当您在浏览器中输入 subdomain.hostone.com 时,它将使用 DNS 获取其 IP 地址(如果是 CNAME,它将继续尝试,直到从 A 记录获取 IP),然后它将连接到该 IP 并发送 http 请求

Host: subdomain.hostone.com 

http 标头中的某处。

You can only make DNS name pont to a different IP address, so if You you are using virtual hosts redirecting with DNS won't work.

When you enter subdomain.hostone.com in your browser it will use DNS to get it's IP address (if it's a CNAME it will continue trying until it gets IP from A record) then it will connect to that IP and send a http request with

Host: subdomain.hostone.com 

somewhere in the http headers.

五里雾 2024-07-11 07:35:20

设置 301 重定向可能是最好/最简单的方法。 无需 DNS 黑客攻击。

It's probably best/easiest to set up a 301 redirect. No DNS hacking required.

耶耶耶 2024-07-11 07:35:20

我认为有几个答案围绕着您的问题的可能解决方案。

我同意最简单的(也是 SEO 目的的最佳解决方案)是 301 重定向。 在 IIS 中,这相当简单,您可以为 subdomain.hostone.com 创建一个站点,创建站点后,右键单击该站点并进入属性。 单击打开的站点属性窗口的“主目录”选项卡。 选择单选按钮“重定向到 URL”,输入新站点的 url (http://subdomain.hosttwo.com ),然后选中“上面输入的确切 URL”、“此资源的永久重定向”复选框(第二个复选框会导致 301 重定向,而不是 302 重定向)。 单击“确定”,即可完成。

或者,您可以使用以下方法之一在 http://subdomain.hostone.com 网站上创建一个页面方法(取决于托管平台支持的方式)

PHP 重定向:


<?
Header( "HTTP/1.1 301 Moved Permanently" ); 
Header( "Location: http://subdomain.hosttwo.com" ); 
?>

ASP 重定向:


<%@ Language=VBScript %>
<%
Response.Status="301 Moved Permanently"
Response.AddHeader "Location","http://subdomain.hosttwo.com"
%>

ASP .NET 重定向:


<script runat="server">
private void Page_Load(object sender, System.EventArgs e)
{
Response.Status = "301 Moved Permanently";
Response.AddHeader("Location","http://subdomain.hosttwo.com");
}
</script>

现在假设您的 CNAME 记录已正确创建,那么您遇到的唯一问题是为 http://subdomain.hosttwo.com 使用共享 IP 和主机标头来确定应显示哪个站点。 要在 IIS 下解决此问题,请在 Web 服务器上的 IIS 管理器中右键单击 subdomain.hosttwo.com 站点,然后单击“属性”。 在显示的“网站”选项卡上,您应该会在需要单击的 IP 地址旁边看到一个“高级”按钮。 在出现的“高级网站识别”窗口中,单击“添加”。 选择已被 subdomain.hosttwo.com 使用的相同 IP 地址,输入 80 作为 TCP 端口,然后输入 subdomain.hosttwo.com 作为主机标头值。 单击“确定”,直到返回 IIS 管理器主窗口,然后就可以开始了。 打开浏览器,然后浏览到 http://subdomain.hostone.com,您将看到该站点:即使您的网址显示 http://subdomain.hosttwo.com subdomain.hostone.com" rel="noreferrer">http://subdomain.hostone.com

希望有帮助...

I think several of the answers hit around the possible solution to your problem.

I agree the easiest (and best solution for SEO purposes) is the 301 redirect. In IIS this is fairly trivial, you'd create a site for subdomain.hostone.com, after creating the site, right-click on the site and go into properties. Click on the "Home Directory" tab of the site properties window that opens. Select the radio button "A redirection to a URL", enter the url for the new site (http://subdomain.hosttwo.com), and check the checkboxes for "The exact URL entered above", "A permanent redirection for this resource" (this second checkbox causes a 301 redirect, instead of a 302 redirect). Click OK, and you're done.

Or you could create a page on the site of http://subdomain.hostone.com, using one of the following methods (depending on what the hosting platform supports)

PHP Redirect:


<?
Header( "HTTP/1.1 301 Moved Permanently" ); 
Header( "Location: http://subdomain.hosttwo.com" ); 
?>

ASP Redirect:


<%@ Language=VBScript %>
<%
Response.Status="301 Moved Permanently"
Response.AddHeader "Location","http://subdomain.hosttwo.com"
%>

ASP .NET Redirect:


<script runat="server">
private void Page_Load(object sender, System.EventArgs e)
{
Response.Status = "301 Moved Permanently";
Response.AddHeader("Location","http://subdomain.hosttwo.com");
}
</script>

Now assuming your CNAME record is correctly created, then the only problem you are experiencing is that the site created for http://subdomain.hosttwo.com is using a shared IP, and host headers to determine which site should be displayed. To resolve this issue under IIS, in IIS Manager on the web server, you'd right-click on the site for subdomain.hosttwo.com, and click "Properties". On the displayed "Web Site" tab, you should see an "Advanced" button next to the IP address that you'll need to click. On the "Advanced Web Site Identification" window that appears, click "Add". Select the same IP address that is already being used by subdomain.hosttwo.com, enter 80 as the TCP port, and then enter subdomain.hosttwo.com as the Host Header value. Click OK until you are back to the main IIS Manager window, and you should be good to go. Open a browser, and browse to http://subdomain.hostone.com, and you'll see the site at http://subdomain.hosttwo.com appear, even though your URL shows http://subdomain.hostone.com

Hope that helps...

心不设防 2024-07-11 07:35:20

尝试将其更改为“subdomain -> subdomain.hosttwo.com”

CNAME 是某个域的别名,因此当您转到 hostone.com 的控制面板时,您不应该将整个名称输入到 CNAME 别名中。

至于您收到的错误,您可以登录 subdomain.hostwo.com 并检查日志吗?

Try changing it to "subdomain -> subdomain.hosttwo.com"

The CNAME is an alias for a certain domain, so when you go to the control panel for hostone.com, you shouldn't have to enter the whole name into the CNAME alias.

As far as the error you are getting, can you log onto subdomain.hostwo.com and check the logs?

童话里做英雄 2024-07-11 07:35:20

如今,许多网站所有者都在使用 CDN 服务,从 CDN 服务器提取数据。 如果是这种情况,那么您有两个选择:

  1. 创建子域并通过添加 CNAME 记录编辑 DNS

  2. 不创建子域但仅创建指向您临时 DNS 网址的 CNAME 记录。

此解决方案仅意味着从 CDN 中提取代码,这将显示它正在从 cdn.sitename.com 获取数据,但实际上它是从您的 CDN 主机中提取的。

These days, many site owners are using CDN services which pulls data from CDN server. If that's your case then you are left with two options:

  1. Create a subdomain and edit DNS by Adding a CNAME record

  2. Don't create a subdomain but only create a CNAME record pointing back to your temporary DNS URL.

This solution only implies to pulling code from CDN which will show that it's fetching data from cdn.sitename.com but practically its pulling from your CDN host.

哆兒滾 2024-07-11 07:35:20

听起来 hosttwo.com 上的 Web 服务器不允许传递未定义的域。 您还说您想要进行重定向,这实际上不是重定向的方法。 如果您通过 GoDaddy 购买了此域名,您可能只想使用他们的重定向服务。

It sounds like the web server on hosttwo.com doesn't allow undefined domains to be passed through. You also said you wanted to do a redirect, this isn't actually a method for redirecting. If you bought this domain through GoDaddy you may just want to use their redirection service.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文