当前位置: 动力学知识库 > 问答 > 编程问答 >

.htaccess - htaccess mod_rewrite: Redirect all subdomains, exclude some

问题描述:

There are many similar questions, but I couldn't find an answer to this specific one:

In my .htaccess I have a rewrite to redirect all subdomains to http://example.com:

RewriteCond %{HTTP_HOST} !^example\.com$ [NC]

RewriteRule ^(.*)$ http://example.com/$1 [L,R=301]

But I want it to ignore dev.example.com (and maybe some other subdomains). I guess that's easy, but I can't figure it out.

网友答案:

Same way as you excluded the main domain:

RewriteCond %{HTTP_HOST} !^example\.com$ [NC]
RewriteCond %{HTTP_HOST} !^dev\.example\.com$ [NC]
RewriteRule ^(.*)$ http://example.com/$1 [L,R=301]
分享给朋友:
您可能感兴趣的文章:
随机阅读: