apache redirect from non www to www

前端 未结 24 1188
春和景丽
春和景丽 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 06:52

    To remove www from your URL website use this code in your .htaccess file:

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

    To force www in your website URL use this code on .htaccess

    RewriteEngine On
    RewriteBase /
    RewriteCond %{HTTP_HOST} ^YourSite.com$
    RewriteRule ^(.*)$ http://www.yourSite.com/$1 [R=301]
    RewriteCond %{REQUEST_fileNAME} !-d
    RewriteCond %{REQUEST_fileNAME} !-f
    RewriteRule ^(([^/]+/)*[^./]+)$ /$1.html [R=301,L]
    

    Where YourSite.com must be replaced with your URL.

提交回复
热议问题