REQUEST_URI issues with IIRF

Topics: Developer Forum, User Forum
Nov 8, 2009 at 5:42 PM

With my site i take all pages and redirect them to /index.php. And i parse the url to figure out which pages to load etc..

Normally (with htaccess) i can use $_SERVER['REQUEST_URI'] to access the actual url that was asked for. With iirf $_SERVER['REQUEST_URI'] gets set to the rewritten url. to get past this i've been rewriting my urls like this

RewriteRule (.*) /index.php?REQUEST_URI=$1

And using the Get variable REQUEST_URI to load my pages

The problem with this is that if the url has a query string it gets written as


and now my GET variables are messed up. it eats the first one because of the first ?

In short...Is there anyway i can get the actual requested uri using iirf?

Nov 8, 2009 at 10:36 PM

You've got a couple options:

  • You can retrieve the original pre-rewrite URL with $_SERVER['HTTP_X_REWRITE_URL'] , if you've used the [U] flag on your rule.   
  • you can use the pattern to match on the query string and append it appropriately.

Ex 1:

RewriteRule ^/(.+)$  /index.php  [U]

Ex 2:

RewriteRule ^/(.+)\??(.*)?$  /index.php?ORIG_REQUESTPATH=$1&ORIG_QUERYSTRING=$2
Nov 9, 2009 at 4:38 AM

works perfect. thanks so much. thanks for making iirf as well, not sure what i would do without it.

Nov 9, 2009 at 5:04 AM
Edited Nov 9, 2009 at 5:25 AM

I'm glad it works for you!

I know what you would do, without IIRF:  you'd pay for a different product !!!


Nov 9, 2009 at 4:32 PM

Ok i noticed that my GET variables are completely gone when using

RewriteRule ^(.*)$ /index.php [U]

when i use

RewriteRule ^/(.+)\??(.*)?$  /index.php?ORIG_REQUESTPATH=$1&ORIG_QUERYSTRING=$2 [U]

my get variables are incoherent.

    [ORIG_REQUESTPATH] => index.php?ORIG_REQUESTPATH=index.php?ORIG_REQUESTPATH=index.php?ORIG_REQUESTPATH=index.php?ORIG_REQUESTPATH=index.php?ORIG_REQUESTPATH=index.php?ORIG_REQUESTPATH=index.php?ORIG_REQUESTPATH=index.php?ORIG_REQUESTPATH=ceramide/view-all/?backpage=3

im using iirf v2


Nov 9, 2009 at 6:50 PM

I've been messing around with the rewriterule regex and this seems ot be working well

RewriteRule ^.*?(?:\?(.*))?$  /index.php?$1 [U]

Nov 9, 2009 at 9:02 PM
Edited Nov 9, 2009 at 9:04 PM


yes - in the original rule, you don't pass along the original query string, so it is just.. lost.  You rewrite every incoming request to index.php (no query string at all).  So you understand why the query string disappears.

In your updated rule, you append the original query string, but ... remember the rules in the ini file are processed iteratively,  Every time the rule matches, it appends the original query string, but each iteration through, the original query string is longer.  If you know what I mean.   You would be able to see this by examining the log file.

I think what you want is either the [QSA] (query-string-append) modifier, like so:

RewriteRule ^/(?!index.php)(.*)$   /index.php    [U,QSA]

This is almost like referencing the QUERY_STRING variable, like so:

RewriteRule ^/(?!index.php)(.*)$   /index.php?%{QUERY_STRING}    [U]

Except that QSA does not append an unnecessary ? when the QUERY_STRING is empty.  Notice in both cases you need to prevent infinite recursion by NOT allowing the rule to match in the case that the incoming URL is index.php already.

Your more complex rule will probably work, except it is harder to read.