的.htaccess要求WWW的域名,但让子域,如果存在没有硬编码 [英] .htaccess to require WWW for domain, but allow subdomain if existing with no hard coding
问题描述
我试图弄明白如何建立一个.htaccess的一套规则,这将迫使域中前面的WWW的presence如果最初没有规定,但在同一的时候,它不会有任何影响,如果一个子域是pressent;这一切,没有硬编码任何域名,这样的脚本是可移植到不同的服务器和配置。
I'm trying to figure it out how to set up an .htaccess set of rules that would force the presence of the "www" in front of the domain if it is not initially specified, but at the same time, it will not have any effect if the an subdomain is pressent; all this without hard coding any domain name so that the script is portable around different servers and configurations.
编辑:
对不起,我没能得到这个解释就在拳头的地方。所以,我需要的是如下:
I'm sorry I was not able to get this explained right in the fist place. So what I need is as follows:
http://example.com - >重定向到的 http://www.example.com
http://example.com -> redirects to http://www.example.com
http://www.example.com - >不重定向
http://subdomain.example.com - >不重定向
推荐答案
这的mod_rewrite 规则应该做它的二级域名:
This mod_rewrite rule should do it for second level domains:
RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
这篇关于的.htaccess要求WWW的域名,但让子域,如果存在没有硬编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!