[Nottingham] Apache / mod_rewrite / php and environment variables

David Aldred david at familyaldred.org.uk
Sun Dec 17 17:25:02 GMT 2006

Setup: Locally, Apache 2.2.3 and PHP 5.1.6 on Kubuntu Edgy;  same problem 
applies on my webhost (I don't know exactly which versions of Apache and 
Linux are in use there; they have PHP4).

I'm having a bit of trouble with using mod_rewrite to set environment 
variables, then php to read them...

.htaccess in directory 'test' contains:

	RewriteEngine On
	RewriteRule ^w/S=([^/]+)/(.*) w/$2 [env=STATUS:$1]

..which should take http://aldred.org/test/w/S=mysite/index.php and convert it 
to http:/aldred.org/test/w/index.php, with the environment variable 'STATUS' 
set to 'mysite'.

aldred.org/test/w/index.php just has:
	echo "Hello, World.";

aldred.org is based on my webhost, and the result of 
http://aldred.org/test/w/S=mysite/index.php is 'Hello World', followed by a 
listing of a lot of stuff - but no variable called 'STATUS'.  Using a locally 
hosted version, the precise output is different (of course), but still 
no 'STATUS'.

It seems that mod_rewrite is doing its job in rewriting the URL, but PHP 
either the environment variable isn't being set or PHP can't read it.

Where's it gone? Or am I missing something obvious (again!)? 
David Aldred

More information about the Nottingham mailing list