mod_rewrite - rewrite all subdomains except "m" to something

时间:2015-07-28 16:18:06

标签: .htaccess mod-rewrite

I have this rule for rewriting all subdomains to some URL, but I would like to edit it to rewrite all subdomains except subdomain "m".

RewriteCond %{HTTP_HOST} ^(.*)\.myweb\.cz
RewriteRule ^(.*)$ http://myweb.cz/adverts/%1/$1 [L,NC,QSA,R=301]

Thanks everyone.

2 个答案:

答案 0 :(得分:0)

Try this htaccess

RewriteCond %{HTTP_HOST} !^m\.myweb\.cz$ [NC]
RewriteCond %{HTTP_HOST} ^([^.]+)\.myweb\.cz$
RewriteRule ^(.*)$ http://myweb.cz/adverts/%1/$1 [L,NC,QSA,R=301]

答案 1 :(得分:0)

You can add a negative lookahead in your condition to avoid matching m.:

RewriteCond %{HTTP_HOST} ^((?!m\.)[^.]+)\.myweb\.cz$ [NC]
RewriteRule ^(.*)$ http://myweb.cz/adverts/%1/$1 [L,R=301]