问题
Hello I try to redirect my domain name from non-www to www via .htaccess file. My previous htaccess code was
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
I replace it by the code
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.forexfunction\.com
RewriteRule (.*) http://www.forexfunction.com/$1 [R=301,L]
but i face 404 errors after replacing this code. How can i solve my problem? Thanks in advance.
回答1:
This is the code which will redirect non-www request to www request.
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]
Here is how you .htacccess file will look like.
<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>
Hope it helps.
来源:https://stackoverflow.com/questions/36811573/how-redirect-no-www-url-to-www-url-in-laravel