how can redirect domain non-www to www in laravel 4?

后端 未结 1 441
春和景丽
春和景丽 2021-01-24 18:54

Hello I try to redirect my domain name from non-www to www via .htaccess file. My previous htaccess code was


    RewriteEngine on         


        
1条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-24 19:23

    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.

    
      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]
    
    
    

    Hope it helps.

    0 讨论(0)
提交回复
热议问题