« Date conversion - PHP | Main | Dates, times, clickable diarys in PHP »
December 27, 2006
Passing GET parameters through Apache mod_rewrite
If you're using Apache mod_rewrite to redirect a series of URLs to a single script, did you know that you can pass values entered onto a form via the GET method through as well? Simply add on %{QUERY_STRING} onto the end of your new URL. You'll need to add a ? into the target URL to ensure that the query string is taken as such .... and you can even add more parameters if you wish.
Here's how we divert all requests to .htm, .html, .php, .php4 and .php5 files in a directory to a single script called b.php; we pass in any parameters the user filled in on his web page, and we generate an extra request parameter called pagename that contains ... of course ... the name of the page requested.
RewriteEngine On
RewriteRule ^(.*)\.htm b.php?pagename=$1&%{QUERY_STRING}
RewriteRule ^(.*)\.php b.php?pagename=$1&%{QUERY_STRING}
Posted by gje at December 27, 2006 01:05 PM
Comments
I just got the contents of your blog as spam. Presumably they put it in to get past filters. Then they attached a "stock tip" (the spam payload) as a GIF.
Posted by: Anonymous at December 28, 2006 01:58 AM
Thanks, 'Anon' .... it's published on the web so I guess anyone can illicitly copy and paste it; not much I can do about that. Just one step further than simply ripping of someone's email address. Constructive suggestions welcomed ...
Posted by: graham Ellis at December 28, 2006 09:44 PM
that's just what i needed.
Thanks.
Posted by: Alex Baskov at January 30, 2008 02:57 PM