Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何强制www.with.htaccess?_.htaccess_Redirect_No Www_Public Html - Fatal编程技术网

如何强制www.with.htaccess?

如何强制www.with.htaccess?,.htaccess,redirect,no-www,public-html,.htaccess,Redirect,No Www,Public Html,我环顾四周,似乎没有人遇到与我相同的问题 我使用了: RewriteEngine on RewriteCond %{HTTP_HOST} ^yoursite.com [NC] RewriteRule ^(.*)$ http://www.yoursite.com/$1 [R=301,L] 然而,当我导航到yoursite.com时,我会被带到www.yoursite.com/public\u html,而这并不存在 以下是我的目录结构: / | .htaccess | | public_html

我环顾四周,似乎没有人遇到与我相同的问题

我使用了:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^yoursite.com [NC]
RewriteRule ^(.*)$ http://www.yoursite.com/$1 [R=301,L]
然而,当我导航到
yoursite.com
时,我会被带到
www.yoursite.com/public\u html
,而这并不存在

以下是我的目录结构:

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

您只需将
.htaccess
文件移动到
public\u html
文件夹中即可。

尝试以下操作:

RewriteCond %{HTTP_HOST} !^www\.yoursite\.com$ [NC]
建议该结构:

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中还有其他指令。我有缓存控制、gzip和IP块。如果我把它移走,会不会有东西断了?