user398314
user398314

Reputation: 367

How do I create a regular expression to negate a string but include anything else

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

Upvotes: 1

Views: 315

Answers (2)

Jan Goyvaerts
Jan Goyvaerts

Reputation: 21999

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.

Upvotes: 1

msurovcak
msurovcak

Reputation: 481

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.

Upvotes: 0

Related Questions