Forum Moderators: phranque
For example www.widget.com/widget.php?color=green or www.widget.com/widget.php?color=red are to be mod-rewriten to www.widget.com/widget.php yet the value of the variable "color" is still passed in the background and can be "output" on the widget.php page example: Looking for green widgets?
Can anyone point me in the right direction.
I get the impression you don't need to look into environment variables, however, I do take it from what you've said that you want to wrap a redirect up in a .htaccess file using mod_rewrite...
The way I'm thinking about this at the moment is it depends on the version of apache you are running to how you could do this, theres a number of subtle differences as always, what version are you running?
Also you know within PHP you can pick the value of any key:value pairs on the query string by calling its key name... so what version of PHP are you running? Anyway as always with a big warning to check any params before directly out putting it into your page... ;)
Anyway, try looking at 'qsappendĤQSA' in the Apache docs under RewriteRule if you want to push on more data to an existing query string, or try looking at %{QUERY_STRING} and just append that you you final redirect when all conditions 'RewriteCond' have been met. However, if you wanted to remove the previous query string to nothing then just put a? at the end of the final redirected uri.
Anyway, let us know what you're thinking,
cheers, matc
I'm running PHP4. Yes, in the meantime I have found it's not an environment variable that gets set maybe it's a global variable?
Basically I'm trying to redirect
widgets.php?key=green
to
widgets.php
most likely with mod rewrite, but before redirecting setting a variable (in the background) to "green"(or whatever key happens to be) which get passed and can be accessed via php and output to the widgets.php page.
I believe that to set a environment variable and redirect at the same time within Apache you could try something like this... I'm more use to apache2 thou..
Untested of course :)
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} ^widgets.php$
RewriteCond %{QUERY_STRING} colour=([a-z]+)
RewriteRule ^(.*)$ widgets.php? [E=set.env.var:%1,R,L]
However, if you just wanted to set an environment variable without the redirect you could do something like...
RewriteRule ^(.*)$ - [E=set.env.var:%1,L]
Cheers, matc
Forgot but heres something worth a look for accessing Env variables from within PHP... you could use this..
[uk.php.net...]
cheers, matc
The only ways to pass 'session' information from an initial client request to a subsequent client request is by using cookies. And of course, this won't work if the client has disabled cookies...
I would re-examine your need to do this redirect, and decide if it is worth the complications it causes. You might be happier implementing the more common 'search engine friendly' static URLS like many other sites. This subject is well-covered here, and a search on WebmasterWorld will turn up dozens of threads on the subject.
Jim
A redirect terminates the current HTTP request and tells the client (browser, robot, etc) to make a new request.
Apache has no memory of previous requests, and has no expectations of subsequent requests.
It handles one request, finishes that, then handles another request. Within Apache, the second request is handled as if the first request never happened.
So Apache cannot remember anything that happened in the first request while handling the second request.
Solutions require action outside of Apache, either by the client, or by a server-side script.
The three general solutions are:
Those are the only ways to pass information from one request to the next.
Jim