Redirecting Subdomain to WWW using .htaccess

荒凉一梦 提交于 2019-12-12 04:49:48

问题


I'm trying to redirect a specific subdomain to www. I already have rules in place that will redirect non-www to www.domain.com. Here is what I currently have, and it works fine:

RewriteCond %{HTTP_HOST} !^www\.               [NC]
RewriteCond %{HTTP_HOST} ^([^.]+\.[a-z]{2,6})$ [NC]
RewriteRule ^(.*)$       http://www.%1/$1      [R=301,L]

My problem is that some requests are coming in for ns2.domain.com, and I would like those redirected to www.domain.com as well. Any help?


回答1:


Try adding an extra [^.]+\. in your second condition:

RewriteCond %{HTTP_HOST} !^www\.               [NC]
RewriteCond %{HTTP_HOST} ^[^.]+\.([^.]+\.[a-z]{2,6})$ [NC]
RewriteRule ^(.*)$       http://www.%1/$1      [R=301,L]


来源:https://stackoverflow.com/questions/27933536/redirecting-subdomain-to-www-using-htaccess

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