Strange behavior of nested <If> directives and mod_rewrite

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi

I have the following setup in my httpd.conf inside the <Directory
"/usr/local/apache2/htdocs">:
----
    RewriteEngine on
    RewriteRule ^nonexists.php$ /target.php?nonexists
    RewriteRule ^exists.php$ /target.php?exists

    <If "%{HTTP_COOKIE} != 'pear'" >
        Header always set x-request-first-if "YES"
        <If "%{HTTP_USER_AGENT} != 'apple'" >
            Header always set x-request-second-if "YES"
        </If>
        <Else>
            Header always set x-request-second-if "NO"
        </Else>
    </If>
----

The document root has the following files:
exists.php
target.php


Requesting these URL gives the following result:
GET nonexists.php:
x-request-first-if: YES

GET exists.php:
x-request-first-if: YES

GET target.php:
x-request-first-if: YES
x-request-second-if: YES

Expected result: Nested if also gets evaluated even for rewritten requests.


It even gets a little "spookier". Added a "dummy if" on the
REDIRECT_STATUS and now its working:
----
    RewriteEngine on
    RewriteRule ^nonexists.php$ /target.php?nonexists
    RewriteRule ^exists.php$ /target.php?exists

    <If "%{ENV:REDIRECT_STATUS} == 200">
    </If>
    <If "%{HTTP_COOKIE} != 'pear'" >
        Header always set x-request-first-if "YES"
        <If "%{HTTP_USER_AGENT} != 'apple'" >
            Header always set x-request-second-if "YES"
        </If>
        <Else>
            Header always set x-request-second-if "NO"
        </Else>
    </If>
----

GET nonexists.php:
x-request-first-if: YES
x-request-second-if: YES

GET exists.php:
x-request-first-if: YES
x-request-second-if: YES

GET target.php
x-request-first-if: YES
x-request-second-if: YES


Could someone explain to me what this behavior is exactly?

I get the same behavior for FreeBSD apache 2.4.62 and the httpd:2.4.62
docker image. I could easily provide my containerized test-setup if
needed.

Thanks for your help.
- Pascal

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@xxxxxxxxxxxxxxxx
For additional commands, e-mail: users-help@xxxxxxxxxxxxxxxx




[Index of Archives]     [Open SSH Users]     [Linux ACPI]     [Linux Kernel]     [Linux Laptop]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Squid]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]

  Powered by Linux