Alex Rivera | Logout

REQUEST_URI is not overridden by using APACHE RewriteRule?

Asked 2011-05-03T03:47:04.657
10

Problem :

Am using Kohana/PHP to develop a hosted website for other companies. I get the customer to put in a CNAME entry in their DNS server to point to my domain. Eg. http://invites.somecompany.com is pointing to http://www.mydomain.com.

Thus, the %{HTTP_HOST} entry on my apache server is 'invites.somecompany.com'

I want to rewrite http://invites.somecompany.com/invite to http://www.mydomain.com/invites/invite

Even though Apache seems to be doing that, the $_SERVER['REQUEST_URI'] is still "/". The problem is Kohana uses $_SERVER['REQUEST_URI'] to route the request to the appropriate controller code. In this case, it routes it to the base index controller, instead of the 'invites' controller.

Facts :

The Apache mod_rewrite directives i am using (in the .htaccess file) :-

RewriteCond %{HTTP_HOST} !^www.mydomain.com$
RewriteCond %{REQUEST_URI} !.*invites.*
RewriteRule ^(.*)$ invites/$1

# For Kohana
RewriteRule .* index.php?kohana_uri=$0 [PT,QSA,L]

in the index.php, i do :

var_dump($_SERVER);

and i get :

'REQUEST_URI' => string '/',
'QUERY_STRING' => string 'kohana_uri=invites/index.php&kohana_uri=invites/invite'
'REDIRECT_QUERY_STRING' => string 'kohana_uri=invites/invite'

So the mod_rewrite does not modify the REQUEST_URI ?

Need :

'REQUEST_URI' => 'invites/invite',
'QUERY_STRING' => string 'kohana_uri=invites/invite',

How do I get that?

====================== Edit

Rewrite Log Entries :-

strip per-dir pref
Edit
Report

1 Answer

0

Because of the way mod_rewrite works, you can't have it in $_SERVER['REQUEST_URI'] immediately. If you're happy to modify $_SERVER (which is sometimes considered a bad idea), how about something like this:

$_SERVER['REQUEST_URI'] = $_GET['kohana_uri'];
$_SERVER['QUERY_STRING'] = $_SERVER['REDIRECT_QUERY_STRING'];
answered 2011-05-20T18:25:20.097

Your Answer