QSA in IIRF compared to htaccess

Dec 20, 2011 at 8:32 PM

Hi!

I've been wondering sometime now about the current logic in the QSA-modifier.

Example rewrite-rule:

RewriteRule ^/foo$ /foo.php [QSA,L]

This rule will only match against /foo. It will not match against /foo?a=b. However, on Apache the result is different. On Apache, this rule will also match against /foo?a=b, resulting in it being rewritten to /foo.php?a=b (hence the QSA-modifier).

Am I doing something wrong here or is QSA-modifier in IIRF simply not compatible to Apache?

 

Coordinator
Dec 22, 2011 at 5:37 PM

QSA is "query string append" and refers to appending the query string to the result of the rule.

I don't know exactly how it works in Apache, but that is how it works in IIRF.

If you want to match on a URL that has or does not have a query string, you can simply use a modified regular expression.

Something like this:

RewriteRule ^/foo($|\?)  /foo.php  [QSA,L]

That rule matches /foo, with no query string or /foo?... with anything following it.

Dec 22, 2011 at 11:13 PM

Thanks for the quick response and your effort. I know how to modify the RewriteRule to make it work. My problem in this case is incompatibility between IIRF and other rewriting-methods (Apache and such), causing the need to modify rewrite-rules when migrating from a different environment to IIRF when using the QSA-modifier like this.

Afaik when using QSA it should match ^/foo$ when requesting /foo aswell as /foo?a=b. If this is not the case then using the QSA-modifier would make no sense when using RewriteRule ^/foo$.  When using Google to find out whether there's official documentation on this I can't find anything really relevant to my issue other than http://httpd.apache.org/docs/current/rewrite/flags.html#flag_qsa. All I know is that I've seen lots of .htaccess-files which use QSA and RewriteRules ending with $ not including the querystring.

What I'm trying to accomplish is that IIRF would match /foo?a=b on RewriteRule ^/foo$ /foo.php [QSA,L]. When not using the QSA-tag, it shouldn't match.

Would you be willing to try to adjust the way IIRF behaves around QSA?

Coordinator
Dec 24, 2011 at 8:06 PM

I can understand the desire for consistency.  I haven't seen any rule that says, in Apache, the use of the QSA modifier would somehow modify the meaning of the regex.

> Afaik when using QSA it should match ^/foo$ when requesting /foo aswell as /foo?a=b.

I don't know what that means.  When you say, "It should match..." what exactly does "It" refer to?    QSA does a specific thing, append the query string to the result. I am not aware that QSA implies "append a query string to the regex".   I may simply be unaware of that accepted meaning.

I would be willing to modify the QSA behavior in IIRF if I can see a clear description of the QSA semantics in the Apache documentation, which indicates the existing IIRF behavior is inconsistent. 

May 16, 2012 at 12:52 PM

I (think I) understand what the problem is now.

http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewriterule

RewriteRule Directive

Pattern is a perl compatible regular expression. On the first RewriteRule, it is matched against the (%-decoded) URL-path (or file-path, depending on the context) of the request. Subsequent patterns are matched against the output of the last matching RewriteRule.

What is matched?

In VirtualHost context, The Pattern will initially be matched against the part of the URL after the hostname and port, and before the query string (e.g. "/app1/index.html").

In Directory and htaccess context, the Pattern will initially be matched against the filesystem path, after removing the prefix that led the server to the current RewriteRule (e.g. "app1/index.html" or "index.html" depending on where the directives are defined).

As I come to understand this, it means that the RewriteRule-pattern should never match the query string (but it can be appended via the QSA-modifier).

Unfortunately, this would mean a drastic change in IIRF if you were to make it fully compatible (and if my explanation is correct), but debating on how to achieve/fix the issue is (as it seems) a complete new issue. There are many possible 'quick fix'-solutions to this problem (if I am correct about the problem), but a full-compatibility-change might be too much for people depending on how it currently works.

Oct 10, 2012 at 5:22 AM
Cheeso wrote:

QSA is "query string append" and refers to appending the query string to the result of the rule.

I don't know exactly how it works in Apache, but that is how it works in IIRF.

If you want to match on a URL that has or does not have a query string, you can simply use a modified regular expression.

Something like this:

RewriteRule ^/foo($|\?)  /foo.php  [QSA,L]

That rule matches /foo, with no query string or /foo?... with anything following it.

Thanhks, that works fine.