我环顾四周,似乎没有人遇到和我一样的问题。
我用过:
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
试试这一行:
RewriteCond %{HTTP_HOST} !^www.yoursite.com$ [NC]
Gumbo在他的回答(如何以通用的方式强制"www."?)中推荐了这样的结构:
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www. [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
您需要做的就是将.htaccess
文件移动到public_html
文件夹