Linked Questions

Popular Questions

Regex in apache mod_rewrite

Asked by At

We have a server that has a few aliases and I've been trying to write a regex that'll match each of these hostnames for a rewrite rule:

dev.domain.com      
www.dev.domain.com    
dev.www.domain.com    

Right now I have the "I dont really know regex" solution of (dev\.www|www\.dev|dev)\.domain\.com

It works, but I know its the least elegant way to do it. The server has about 120 other aliases so it's important I don't do something like (.*)domain\.com and match something like sales.domain.com by accident.

Using a non-capture group I was able to get 2 of the 3 matched but never all 3. I was trying things like (?:www|dev)\.domain\.com but I can't figure out (or find on google) a way to ignore the order. I might be going about it completely the wrong way as well.

Related Questions