Mailing List Archive

RewriteRule and priorities
Hi,

I have a rewriterule like:

RewriteRule ^/blog/(.*) /resources/blog/$1 [L,R=301]

but I also have several instances where there are exceptions. In other
words, I have an article at /blog/ that I want to be redirected to some
place other than /resources/blog. How can I do this?

Order of processing doesn't seem to matter.

Thanks,
Dave

--


DaveWreski

President & CEO

Guardian Digital, Inc.

We Make Email Safe








640-800-9446 <tel:640-800-9446>

dwreski@guardiandigital.com <mailto:dwreski@guardiandigital.com>

https://guardiandigital.com <https://guardiandigital.com>

103 Godwin Ave, Suite 314, Midland Park, NJ 07432




facebook <https://www.facebook.com/gdlinux>

twitter <https://twitter.com/gdlinux>

linkedin <https://www.linkedin.com/company/guardiandigital>
Re: RewriteRule and priorities [ In reply to ]
??, 17 ???. 2023??. ? 05:24, Dave Wreski <dwreski@guardiandigital.com.invalid>:
>
> Hi,
>
> I have a rewriterule like:
>
> RewriteRule ^/blog/(.*) /resources/blog/$1 [L,R=301]
>
> but I also have several instances where there are exceptions. In other words, I have an article at /blog/ that I want to be redirected to some place other than /resources/blog. How can I do this?
>
> Order of processing doesn't seem to matter.

https://httpd.apache.org/docs/2.4/en/mod/mod_rewrite.html#rewriterule
says:
"The order in which these rules are defined is important - this is the
order in which they will be applied at run-time."

Maybe you are missing processing flags, such as "L" or "END".

Flags are documented in more details here:
https://httpd.apache.org/docs/2.4/en/rewrite/flags.html


Note that you can turn on logging, see
https://httpd.apache.org/docs/2.4/en/mod/mod_rewrite.html#logging

Best regards,
Konstantin Kolinko

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org
Re: RewriteRule and priorities [ In reply to ]
El lun, 17 jul 2023 a las 12:09, Konstantin Kolinko (<knst.kolinko@gmail.com>)
escribió:

> ??, 17 ???. 2023??. ? 05:24, Dave Wreski <dwreski@guardiandigital.com
> .invalid>:
> >
> > Hi,
> >
> > I have a rewriterule like:
> >
> > RewriteRule ^/blog/(.*) /resources/blog/$1 [L,R=301]
> >
> > but I also have several instances where there are exceptions. In other
> words, I have an article at /blog/ that I want to be redirected to some
> place other than /resources/blog. How can I do this?
> >
>
>

I would start by defining exceptions first like Konstantino says, but I
would also try to avoid greedy expressions like (.*) which match absolutely
everything and tend to complicate things in the long run.

You can also try to use negative lookahead expressions which are used to
define exceptions like the ones you seem to describe, example:
/blog/(?!whatever_you_want_to_exclude)(.+) /resources/blog/$1 [L,R=301]
(not negative lookahead group is not captured therefore it generates no
variable value.

When dealing with regular expressions a site or somewhere where to test
them is ideal too, I fancy debuggex.com in PCRE mode for example.

--
Daniel Ferradal
HTTPD Project
#httpd help at Libera.Chat