Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In Debugging info is RewriteCond before RewriteRule pattern test #84

Open
kajman-cz opened this issue Mar 11, 2022 · 3 comments
Open

In Debugging info is RewriteCond before RewriteRule pattern test #84

kajman-cz opened this issue Mar 11, 2022 · 3 comments

Comments

@kajman-cz
Copy link

kajman-cz commented Mar 11, 2022

In Debugging info is RewriteCond before RewriteRule, but the Apache first evaluates the first parameter (pattern) in the RewriteRule and only on match begins to test the conditions in the RewriteCond written before that RewriteRule.

The example lacks pattern testing between steps 1 (RewriteEngine On) and 2 (RewriteCond %{QUERY_STRING} ^qs$).

Manual says:
The rewriting engine loops through the ruleset rule by rule (RewriteRule directives) and when a particular rule matches it optionally loops through existing corresponding conditions (RewriteCond directives). For historical reasons the conditions are given first, and so the control flow is a little bit long-winded.
https://httpd.apache.org/docs/current/rewrite/tech.html#InternalRuleset

@WouterSioen
Copy link
Member

@kajman-cz thanks for creating this issue. Do you have a practical example where this behavior introduces bugs in the htaccess tester? That would help us understand the exact problem a bit better and to implement improvements to the tool.

@kajman-cz
Copy link
Author

Sorry for bad link to example. I edited first post and repair is. The link is now
https://htaccess.madewithlove.com/?share=af2c2630-8373-46bf-a809-71a26ecb791f

There are steps

  1. RewriteEngine On
    RewriteEngine was now turned on for the document.

  2. RewriteCond %{QUERY_STRING} ^qs$
    This condition was not met.

  3. RewriteRule ^index.html$ - [L]
    This rule was not met.

But apache tests pattern in RewriteRule before your step 2.
Apache log (how to enable it):
[perdir D:/data/dev/www/example/] strip per-dir prefix: D:/data/dev/www/example/index.html -> index.html
[perdir D:/data/dev/www/example/] applying pattern '^index\.html$' to uri 'index.html'
[perdir D:/data/dev/www/example/] RewriteCond: input='' pattern='^qs$' => not-matched
[perdir D:/data/dev/www/example/] pass through D:/data/dev/www/example/index.html

@kajman-cz
Copy link
Author

kajman-cz commented Mar 11, 2022

The wrong order of testing probably causes the bug 53.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants