.htaccess to require WWW for domain, but allow subdomain if existing with no hard coding

后端 未结 2 1567
死守一世寂寞
死守一世寂寞 2021-01-14 19:56

I\'m trying to figure it out how to set up an .htaccess set of rules that would force the presence of the \"www\" in front of the domain if it is not initially specified, bu

2条回答
  •  死守一世寂寞
    2021-01-14 20:29

    This mod_rewrite rule should do it for second level domains:

    RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$
    RewriteCond %{HTTPS}s ^on(s)|
    RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
    

提交回复
热议问题