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

♀尐吖头ヾ 提交于 2019-11-26 17:32:40

问题


I have reviewed other posts but cannot find one that fully addresses my needs.

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:


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]


来源:https://stackoverflow.com/questions/12256130/htaccess-redirect-automatically-add-www-if-no-subdomain-exists

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!