DNS 将域重定向到子域 [英] DNS Redirect domain to subdomain

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

问题描述

我正在寻找一种通过 DNS a/cname 记录将域重定向到其子域的方法.

I am looking for a way to redirect a domain to its subdomain via DNS a / cname records.

是否可以完全在 DNS 中完成这些示例,我知道使用 .htaccess 和 PHP 可以轻松完成.

Is it possible to have these examples done totally in DNS, I know it can be easily done with .htaccess and PHP.

website.com => blog.website.com
website.com/hello => blog.website.com/hello
www.website.com => blog.website.com
www.website.com/hello => blog.website.com/hello

有什么想法吗?

推荐答案

DNS 仅用于将域名与 IP 地址相关联.你不能用它做重定向.

DNS is only for associating domain names with an IP address. You cannot do a redirection with it.

您必须在 Web 服务器端处理重定向.你只需要抛出一个 HTTP 301 Permanentlymoved 让你的访问者知道新地址,如果你使用的是 .htaccess 文件,或者一个简单的 PHP 脚本,一个 header() 函数.

You will have to handle the redirection on the web server side. You just need to throw an HTTP 301 Permanently moved to let your visitors know the new address whether with an .htaccess file if you are using apache, or a simple PHP script with an header() function.

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

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