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

后端 未结 2 1548
死守一世寂寞
死守一世寂寞 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:27
    RewriteCond %{HTTP_HOST} ^example\.org
    RewriteRule ^ http://www.example.org%{REQUEST_URI} [L,R=301]
    

    This will not redirect subdomains like mail.example.org

    0 讨论(0)
  • 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]
    
    0 讨论(0)
提交回复
热议问题