apache redirect from non www to www

前端 未结 24 917
春和景丽
春和景丽 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条回答
  •  既然无缘
    2020-11-22 07:16

    Redirect domain.tld to www.

    The following lines can be added either in Apache directives or in .htaccess file:

    RewriteEngine on    
    RewriteCond %{HTTP_HOST} .
    RewriteCond %{HTTP_HOST} !^www\. [NC]
    RewriteRule ^ http%{ENV:protossl}://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
    
    • Other sudomains are still working.
    • No need to adjust the lines. just copy/paste them at the right place.

    Don't forget to apply the apache changes if you modify the vhost.

    (based on the default Drupal7 .htaccess but should work in many cases)

提交回复
热议问题