Hi

Apache processes the RedirectMatch statements from the top of the config file, to the bottom, so the 1st rule is matched first, 2nd rule second, etc, etc (as I'm sure you know).

What this means is that you can add all of your exceptions *above* your original regex, and they will get matched first. Unfortunately, you also need some way of stopping the rules matching again, after the redirect has been followed. This is why I have used the double '//' in the URLs (this does mean that exceptions will look ugly once the redirect has been followed). e.g.

RedirectMatch ^/basedirectory/exceptiondirectory1(.*)$ http://server1/ +basedirectory//exceptiondirectory1$1 RedirectMatch ^/basedirectory/exceptiondirectory2(.*)$ http://server1/ +basedirectory//exceptiondirectory2$1 RedirectMatch ^/basedirectory/(|[^/].*)$ http://server2/basedirectory/ +$1

This will work, but is a bit messy (and doesn't overly improve on your original suggestion).

What would be better is if the problem could be flipped, and you set the redirects up on server2 (but if you don't admin that server, I can see that would be a problem). Then all you would need is:

RedirectMatch ^/basedirectory/exceptiondirectory1(.*)$ http://server1/ +basedirdirectory/exceptiondirectory1$1 RedirectMatch ^/basedirectory/exceptiondirectory2(.*)$ http://server1/ +basedirectory/exceptiondirectory2$1

HTH,

-- Dave :-)


In reply to [OT] Re: apache RedirectMatch (regexp question) by DaveH
in thread apache RedirectMatch (regexp question) by Cmdr_Tofu

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.