views:

48

answers:

2

I'm trying to create a regex for apache that will ignore certain strings, but will use anything else. Ive tried many different methods however i just can't seem to get it correct.

for example

i want it to ignore

ignore.mysite.com

but anything else i want it to use

*.mysite.com

A: 

If you want this regular expressions for mod_rewrite, you can use RewriteCond with negation, just like this:

   RewriteCond %{REMOTE_HOST}  !^ignore.example.com$
   RewriteRule ....

You can find more, of course, in documentation.

msurovcak
I was hoping to do this in the server alias portion of a virtual host
In this case, just define another virtual host ignore.example.com before *.example.com
msurovcak
basically what i have is three sites the default which i want to be either example.com or www.example.com, next i have staging.example.com and finally devel.example.com which i want anything else (devel.example.com or * aside from staging) to be redirected to. Right now i have each one of these sites separated into a separate vhost
+1  A: 

If you want a regex that matches whatever.mysite.com where whatever is any possible hostname, but you want the regex not to match ignore.mysite.com, then try this:

^(?!ignore)[a-z0-9-]+\.mysite\.com

The trick is to use negative lookahead.

Jan Goyvaerts