Ok, so I do mod_rewrite, and I'm in a situation where I need to map any subdomain except one. He begins to look like this.
RewriteCond %{HTTP_HOST} ^([^\.]+)\.example\.com$ [NC]
Thus, to combine and fix one subdomain, there are no periods. But let me say that I do not want to match a subdomain named "dog". I tried to do this with a negative look.
RewriteCond %{HTTP_HOST} ^((?!dog)[^\.]+)\.example\.com$ [NC]
This works, for the most part. dog.example.com no longer matches, which is good. However doggies.example.com is also no longer consistent. This is not good.
I was able to fix this using a negative lookahead in combination with a negative look like this.
RewriteCond %{HTTP_HOST} ^((?!dog)[^\.]+(?<!dog))\.example\.com$ [NC]
It works. As far as I can tell, it works just fine. The fact is, I can’t believe that this is the best way to reach this match. Look and look? Indeed? What is the “right” way to achieve an equivalent expression?
source
share