Apache redirect 301

I created the following RewriteRules:

RewriteCond “%{ENV:reten}” !”=already” RewriteRule
^/[/]c/([^/]+)$ c/$2 [L,NC,R=301,E=reten:already]

RewriteCond “%{ENV:reten}” !”=already” RewriteRule
^//[/]c/([^/]+)$ $1/c/$3
[L,NC,R=301,E=reten:already]

What is happening:
1) user types: http://foo.com/k1/k2/c/k3
2) Apache will redirect to http://foo.com/k1/c/k3 — because the second rule is applied.
3) The above http://foo.com/k1/c/k3 URL will be treaten by Apache and will applied the first rule and will switch it to:
http://foo.com/c/k2

I’d like to redirect only once.
I wonder if it’s possible to check the previous status code, in that case I could check if the previous status code was 301 and not apply the rules.

The desired scenario is:
1) user types: http://foo.com/k1/k2/c/k3
2) Apache will redirect to http://foo.com/k1/c/k3 — because the second rule is applied.

Thx


Source: apache

Leave a Reply