mod_rewrite - add www

前端 未结 3 1648
半阙折子戏
半阙折子戏 2021-01-02 05:03

I\'m trying to force www for my site address with .htaccess:

RewriteCond %{HTTP_HOST} ^mysite\\.com$ [NC]
RewriteRule ^(.*)$ http:/         


        
3条回答
  •  无人及你
    2021-01-02 05:41

    The problem is right here:

    RewriteCond %{HTTP_HOST} ^mysite\.com$ [NC]
    

    ^ specifies the beginning of the string while $ specifies the end.

    In order to make it work you need to have a wildcard select after the .com or .+.

    to reiterate what Alex said:

     
       RewriteCond %{HTTPS} !=on
       RewriteCond %{HTTP_HOST} !^www\..+$ [NC]
       RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
     
    

提交回复
热议问题