views:

455

answers:

2

I'm trying to redirect all requests for /library/ to an external URL except when .pdf files are requested. e.g. www.mysite.com/library/section should redrect to www.externalsite.com but www.mysite.com/library/docs/some_pdf.pdf should serve up the PDF file without a redirect. Here's what I have:

RedirectMatch permanent /library/!(.*\.pdf) http://www.externalsite.com/
+4  A: 

Try this:

RedirectMatch permanent /library/(?!.*\.pdf) http://www.externalsite.com/
chaos
Thankya kindly! That did the trick.
lewsid
I think anchoring the ".pdf" would be a good thing: (?!.*\.pdf(?:\?|$))
Tomalak
Interesting, the docs for mod_alias say it only supports "standard" regexes -- "(?!..)" negative lookahead is a Perl extension. Oh well, good to know that they work too! +1.
j_random_hacker
In Apache 2.2 the docs specify PCRE: http://httpd.apache.org/docs/2.2/glossary.html#regex. Not sure if this was already the case before but simply not documented in 2.0 — what *is* a “standard” regex anyway? BRE?
bobince
@bobince: That's helpful, thanks -- I must have been looking at the 2.0 or even 1.3 docs. And yes, sadly there is no universally agreed "standard" regex that I'm aware of...
j_random_hacker
+1  A: 

You probably want to match the whole path rather than a substring:

RedirectMatch permanent ^/library/(?!.*\.pdf)$ ...
bobince