DevHeads.net

Need a conditional rewrite/redirect rule

I don't write conditional rewrite rules often but this is a case where I need one. My customer wants the affect of:

RedirectMatch permanent ^/foo/bar/(.*)$ http<http://www.example.com/foo/bar/index.html>://www.example.com/foo/bar/file.html<http://www.example.com/foo/bar/index.html>

Which would of course create a redirect loop.

What I want is a conditional rewrite or redirect rule which would send requests for http://www.example.com/foo/bar/<http://www.example.com/foo/bar/>{any file or path} except http://www.example.com/foo/bar/file.html<http://www.example.com/foo/bar/file.html> to <a href="http://www.example.com/foo/bar/file.html" title="http://www.example.com/foo/bar/file.html">http://www.example.com/foo/bar/file.html</a>.

Anyone solved this already and is willing to share?

Darryl Baker
Sr. System Administrator
Distributed Application Platform Services
Project Management Office and Enabling Technologies
Northwestern | Information Technology
1800 Sherman Ave., Suite 600
Evanston, IL 60201-3715
(847) 467-6674
<a href="http://www.it.northwestern.edu" title="www.it.northwestern.edu">www.it.northwestern.edu</a>

Comments

Re: Need a conditional rewrite/redirect rule

By Yann Ylavic at 02/07/2019 - 17:07

On Thu, Feb 7, 2019 at 10:25 PM Darryl Philip Baker
<darryl. ... at northwestern dot edu> wrote:
No need for a rewrite rule, something like:
RedirectMatch permanent ^/foo/bar/(?!file.html$)(.*)$
<a href="http://www.example.com/foo/bar/file.html" title="http://www.example.com/foo/bar/file.html">http://www.example.com/foo/bar/file.html</a>
(where (?!...) stands for not followed by ...)

Regards,
Yann.

Re: Need a conditional rewrite/redirect rule

By Eric Covener at 02/07/2019 - 17:06

On Thu, Feb 7, 2019 at 4:25 PM Darryl Philip Baker
<darryl. ... at northwestern dot edu> wrote:
Here's an example w/ "negative lookahead" in PCRE.

RedirectMatch permanent ^/foo/bar/(?!file.html$)
<a href="http://www.example.com/foo/bar/file.html" title="http://www.example.com/foo/bar/file.html">http://www.example.com/foo/bar/file.html</a>

Re: Need a conditional rewrite/redirect rule

By Darryl Philip Baker at 02/08/2019 - 10:37

After trying to read the gibberish ProofPoint turned your response into, I when to the mailing list archive site.

Thanks.

Darryl Baker (he/him/his)
Sr. System Administrator
Distributed Application Platform Services
Northwestern University
1800 Sherman Ave.
Suite 6-600 – Box #39
Evanston, IL 60201-3715
<a href="mailto:darryl. ... at northwestern dot edu">darryl. ... at northwestern dot edu</a>
(847) 467-6674

On Thu, Feb 7, 2019 at 4:25 PM Darryl Philip Baker
<darryl. ... at northwestern dot edu> wrote:
Here's an example w/ "negative lookahead" in PCRE.

RedirectMatch permanent ^/foo/bar/(?!file.html$)
<a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__www.example.com_foo_bar_file.html&amp;d=DwIBaQ&amp;c=yHlS04HhBraes5BQ9ueu5zKhE7rtNXt_d012z2PA6ws&amp;r=tdje61_VHSXp608oLofeaJnnzo2Sr9_Cdcp70bBEtQ8&amp;m=bfHWYFXFAs_gCtSrNYZGxg6N46vIGLQLwmzneEwE2yE&amp;s=mLGeu_HVTa-0wWBSITg29Wgl345fVYe6hQmVgyzRptM&amp;e=" title="https://urldefense.proofpoint.com/v2/url?u=http-3A__www.example.com_foo_bar_file.html&amp;d=DwIBaQ&amp;c=yHlS04HhBraes5BQ9ueu5zKhE7rtNXt_d012z2PA6ws&amp;r=tdje61_VHSXp608oLofeaJnnzo2Sr9_Cdcp70bBEtQ8&amp;m=bfHWYFXFAs_gCtSrNYZGxg6N46vIGLQLwmzneEwE2yE&amp;s=mLGeu_HVTa-0wWBSITg29Wgl345fVYe6hQmVgyzRptM&amp;e=">https://urldefense.proofpoint.com/v2/url?u=http-3A__www.example.com_foo_...</a>

Re: Need a conditional rewrite/redirect rule

By Yann Ylavic at 02/07/2019 - 17:09

On Thu, Feb 7, 2019 at 11:06 PM Eric Covener < ... at gmail dot com> wrote:
Yeah, or that :)