重定向www.sub.domain.com到sub.domain.com [英] Redirect www.sub.domain.com to sub.domain.com

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

问题描述

我意识到这之前已经<一个讨论href="http://stackoverflow.com/questions/2909600/redirecting-www-subdomain-example-com-to-subdomain-example-com">here. 但我并没有真正得到我所需要的答案的信息。

I realize this has been discussed before here. But I didn't really get the information I needed from the answers there.

我在 sub.domain.com ,我现在已经有人尝试使用访问它的子域的 www.sub.domain.com ,这显然是一个问题。我需要重定向人们试图使用 WWW。 sub.domain.com

I have a subdomain on sub.domain.com, now I have some people trying to access it using www.sub.domain.com, which is obviously a problem. I need to redirect people trying to use www. to sub.domain.com

我没有用的.htaccess或A(主机)/ CNAME,但如果有人能告诉我什么记录,我需要补充,它需要指向什么帮助了很多东西。

I don't have much knowledge with .htaccess or A(Host)/CName but if someone can tell me exactly what records I need to add and what it needs to point to that would help alot.

推荐答案

首先,你需要添加DNS记录(无论是CNAME或A) www.sub 下domain.com 域,<$ C C $>指向同一个地方。这将使它所以当有人去 www.sub.domain.com ,他们去到同一个IP地址 sub.domain.com

First, you need to add DNS records (either CNAME or A) for www.sub under the domain.com domain, to point to the same place as sub. This will make it so when someone goes to www.sub.domain.com, they go to the same IP address as sub.domain.com.

其次,你需要将这个规则添加到htaccess文件在你的web服务器的文档根目录:

Second, you need to add this rule to the htaccess file in your webserver's document root:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.sub\.domain\.com$ [NC]
RewriteRule ^(.*)$ http://sub.domain.com/$1 [L,R=301]

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

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