0

I have the following rules in my .htaccess:

<IfModule mod_rewrite.c>
    RewriteEngine on

    RewriteCond $1 !^index\.php$
    RewriteRule ^(.*)$ index.php?q=$1 [L]
</IfModule>

This sets the query string value q to the request uri (stripping any preceding directories before the one that index.php resides in).

For example: http://localhost/framework/testing sets q=testing.

I would like to change this so that instead of setting a query string, I would like to set an environment variable. I have tried the following but it does not work (the environment var does not get set):

<IfModule mod_rewrite.c>
    RewriteEngine on

    RewriteCond $1 !^index\.php$
    RewriteRule ^(.*)$ index.php [ENV=request:$1,L]
</IfModule>

Oddly enough, the environment var will get set if the request starts with index.php, for example: http://localhost/framework/index.php/testing sets q=index.php/testing

Peter Horne
  • 6,472
  • 7
  • 39
  • 50

1 Answers1

2

Using PATH_INFO (as suggested by @chrono) and slightly different mod_rewrite rules I've got things working as desired!

Modified .htaccess:

<IfModule mod_rewrite.c>
    RewriteEngine on

    RewriteCond $1 !^index\.php
    RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
Peter Horne
  • 6,472
  • 7
  • 39
  • 50