apache redirect from non www to www

前端 未结 24 950
春和景丽
春和景丽 2020-11-22 06:34

I have a website that doesn\'t seem to redirect from non-www to www.

My Apache configuration is as follows:

RewriteEngine On
### re-direct t         


        
24条回答
  •  旧时难觅i
    2020-11-22 07:12

    -If you host multiple domain names (Optional)

    -If all those domain names are using https (as they should)

    -if you want all those domain names to use www dot domainName

    This will avoid doble redirection (http://non www to http://www and then to https://www)

    
    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
    RewriteRule ^(.*)$ https://www.%1$1 [R=301,L]
    
    

    And

    
    RewriteEngine On
    RewriteCond %{HTTP_HOST} !^www\. [NC]
    RewriteRule ^(.*)$ https://www.%{HTTP_HOST}$1 [R=301,L]
    
    

    You should change the redirection code 301 to the most convenient one

提交回复
热议问题