我如何使用htaccess的强制WWW。在多个域 [英] How can I use htaccess to force www. on multiple domains
问题描述
基本上我有我的网络服务器上的文件夹,我分配到新的领域,每当我买他们只有一个index.html和一个图像文件夹。它基本上只是有我的标志,并说该域名正在建设和即将推出。
Basically I have a folder on my webserver that I assign to new domains whenever I buy them that only has an index.html and an images folder. It is basically just has my logo and says the domain is under construction and coming soon.
通常情况下,当我想强制的www。 preFIX我用下面的code:
Normally when I want to force the www. prefix I use the following code:
rewritecond %{HTTP_HOST} ^domain.com [nc]
rewriterule ^(.*)$ http://www.domain.com/$1 [r=301,nc]
这工作得很好,但是我需要明确地写出来的域名。我处理了很多领域,所以我需要code,这将做到这一点不知道域名。我给它一去,但说实话没有得到之一,亲近。
This works fine however I need to explicitly write out the name of the domain. I deal with a lot of domains so I need code that will do this without knowing the domain name. I gave it a go but honestly got no one where close.
推荐答案
试试这个:
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
这篇关于我如何使用htaccess的强制WWW。在多个域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!