使用的.htaccess重定向子域名WWW重定向、域名、htaccess、WWW

2023-09-02 01:01:21 作者:有关等待的设计

我想重定向特定的子域到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]