2014-07-09 79 views
0

我环顾四周,似乎没有人遇到与我一样的问题。如何强制www。与.htaccess?

我用:

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

然而,当我浏览到yoursite.com我得到采取www.yoursite.com/public_html不存在。

这里是我的目录结构:

/ 
| .htaccess 
| 
| public_html 
    | 
    |index.php 

回答

2

尝试用这一行:

RewriteCond %{HTTP_HOST} !^www\.yoursite\.com$ [NC] 

Gumbo in his answer (how to force “www.” in a generic way?)建议报告这样的结构:

RewriteCond %{HTTP_HOST} !^$ 
RewriteCond %{HTTP_HOST} !^www\. [NC] 
RewriteCond %{HTTPS}s ^on(s)| 
RewriteRule^http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L] 
+0

这工作完美,谢谢。 – joshkrz

0

所有你需要做的是.htaccess文件移动到文件夹public_html

+0

我htaccess具有内它的其他指令。我有缓存控制,gzipping和IP块。如果我移动它,会有什么破? – joshkrz