使用的.htaccess重定向子域名WWW [英] Redirecting Subdomain to WWW using .htaccess

查看:110
本文介绍了使用的.htaccess重定向子域名WWW的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想重定向特定的子域到www。我已经到位,将重定向非www到www.domain.com规则。以下是我现在有,它工作正常:

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]

我的问题是,有些请求进来的 ns2.domain.com ,我想这些重定向到www.domain.com为好。任何帮助?

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?

推荐答案

试着增加一个额外的 [^] + \ 在你的第二个条件:

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]

这篇关于使用的.htaccess重定向子域名WWW的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆