与子域htaccess的文件中删除WWW [英] removing www with htaccess file for subdomains

查看:209
本文介绍了与子域htaccess的文件中删除WWW的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个品种,是子域的特定网站的网站。 http://sub.domain.com http://apple.domain.com 等。

I have a variety of sites that are subdomain specific sites. http://sub.domain.com http://apple.domain.com etc.

用户偶尔会抱怨,该网站不能正常​​工作,然后我发现他们去 http://www.sub.domain.com 或的 http://www.apple.domain.com 并予以满足各种各样的服务器错误页面

users occasionally complain that the site is not working and then i find out they went to http://www.sub.domain.com or http://www.apple.domain.com and are met with a server error page of sorts

有什么样的魔力htaccess的我需要打开 http://www.sub.domain.com - > http://sub.domain.com

what kind of htaccess magic do i need to turn http://www.sub.domain.com -> http://sub.domain.com

感谢

* FWIW我没有通过previous问题搜索请求之前,并没有发现我的答案

*fwiw i did search through previous questions before asking and did not find my answer

推荐答案

如果虚拟主机是真的指向同一个文档根目录的www.sub.domain.com和sub.domain.com,你可以放置一个的.htaccess文件具有以下在doc-根内容:

If the VHost is really pointing to the same docroot for www.sub.domain.com and sub.domain.com, you can place a .htaccess-file with following content in the doc-root:

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

这将重定向所有指向该文档根到sub.domain.com

That will redirect all domains which are pointing to this docroot to sub.domain.com

编辑:

有关在一个单独的.htaccess文件的多个子域:

For multiple Subdomains in one single .htaccess-file:

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

这是从头顶未经测试。

这篇关于与子域htaccess的文件中删除WWW的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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