您好我尝试通过.htaccess文件将我的域名从非www重定向到www。 我以前的htaccess代码是
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
我用代码
替换它RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.forexfunction\.com
RewriteRule (.*) http://www.forexfunction.com/$1 [R=301,L]
但是在替换此代码后我面临404错误。 我怎样才能解决我的问题? 提前谢谢。
答案 0 :(得分:4)
这是将非www请求重定向到www请求的代码。
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]
以下是.htacccess文件的外观。
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
希望它有所帮助。