.htaccess redirect - automatically add www. if no subdomain exists

前端 未结 1 1846
独厮守ぢ
独厮守ぢ 2020-11-30 05:25

I need any www. added automatically to my domain ONLY IF a subdomain is not already there. I do want subdomains to bypass this redirect.

How can I do this?

相关标签:
1条回答
  • 2020-11-30 05:47

    To automatically add a www to your domain name when there isn't a subdomain, add this to the htaccess file in your document root:

    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$
    RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [L,R=301]
    
    0 讨论(0)
提交回复
热议问题