Main Content
Passing GET parameters through Apache mod_rewrite Archive - Originally posted on "The Horse's Mouth" - 2006-12-27 13:05:21 - Graham Ellis
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=&%{QUERY_STRING}
RewriteRule ^(.*)\.php b.php?pagename=&%{QUERY_STRING}
Some other articles
P406 - More CGI Programs and Facilities Uploading and Downloading files - changing names (Perl and PHP) Updating a page strictly every minute (PHP, Perl) This article Simple but rugged form handling demo H112 - Further Web Page and Network Handling Moving from mysql to mysqli - simple worked example Passing variable between PHP pages - hidden fields, cookies and sessions Multiple page web applications - maintaining state - PHP Telling which ServerAlias your visitor used - useful during merging domains Easy session example in PHP - keeping each customers data apart 3 digit HTTP status codes - what are they, which are most common, which should be a concern? Sending out an email containing HTML from within a PHP page Downloading a report from the web for further local analysis Uploading a document or image to its own URL via a browser How to build a test harness into your PHP Shipping a test harness with your class in PHP http, https and ajp - comparison and choice Downloading data for use in Excel (from PHP / MySQL) Keeping staff up to date on hotel room status Script to present commonly used images - PHP PHP / Web 2 logging Single login and single threaded models - Java and PHP Copyright and theft of images, bandwidth and members. Simple page password protection - PHP .php or .html extension? Morally Static Pages PHP header() function - uses and new restrictions Updating a page strictly every minute (PHP, Perl) Improving searches - from OR to AND? PHP Image upload script This article Global, Superglobal, Session variables - scope and persistance in PHP Of course I'll tell you by email Image maps for navigation - a straightforward example Hot answers in PHP Finding the language preference of a web site visitor Adding PHP tags to an old cgi program PHP - setting sort order with an associative array Using PHP to output images, XML, Style sheets, etc Morning image, afternoon image Daily Image Santafied Setting the file name for a downloaded document Accessing a page via POST from within a PHP script Server side scripting of styles to suit the browser Caching an XML feed Reading a news or blog feed (RSS) in your PHP page What brings people to my web site? Time calculation in PHP Sudoku helper or sudoku cheat Spotting a denial of service attack What language is this written in? When to use Frames A607 - Apache httpd mod_rewrite Forwarding a whole domain, except for a few directories - Apache http server Adding a passcode to a directory Telling which ServerAlias your visitor used - useful during merging domains Simplest ever proxy configuration? Finding and diverting image requests from rogue domains How to set up short and meaningfull alternative URLs Redirecting a page - silent, temporary or permanent? Dynamically watching your web site via a PHP wrapper Carrying a long URL around - looking for memorable shorts Redirecting a home page using mod_rewrite Bookkeeping If you have a spelling mistake in your URL / page name mod_rewrite for newcomers Pointing all the web pages in a directory at a database More HowTo diagrams - MySQL, Tomcat and Java Apache httpd, MySQL, PHP - installation procedure What to do if the Home Page is missing Using a MySQL database to control mod_rewrite via PHP Choosing between mod_proxy and mod_rewrite Simple but effective use of mod_rewrite (Apache httpd) This article Apache httpd and Apache Tomcat together tips Clustering, load balancing, mod_rewrite and mod_proxy Using different URLs to navigate around a single script Apache httpd to Tomcat - jk v proxy A603 - Further httpd Configuration Identifying and clearing denial of service attacks on your Apache server Helping search engines with appropriate 400 error codes Building up from a small PHP setup to an enterprise one Forwarding a whole domain, except for a few directories - Apache http server Parse error: parse error, unexpected T_STRING on brand new web site - why? Apache Internal Dummy Connection - what is it and what should I do with it? An image from a website that occasionally comes out as hyroglyphics Redirecting a page - silent, temporary or permanent? How did I do THAT? Monitoring and loading tools for testing Apache Tomcat Database connection Pooling, SSL, and command line deployment - httpd and Tomcat Moving a directory on your web site How to avoid duplicating web page maintainance mod_rewrite for newcomers mod_proxy_ajp and mod_proxy_balancer examples Pointing all the web pages in a directory at a database mod_proxy and mod_proxy_ajp - httpd WEB-INF (Tomcat) and .htaccess (httpd) Configuring Apache httpd What to do if the Home Page is missing User and Group settings for Apache httpd web server Strange behaviour of web directory requests without a trailing slash Default file (MiMe types) for Apache httpd and Apache Tomcat Online hotel reservations - Melksham, Wiltshire (near Bath) Which modules are loaded in my Apache httpd Using a MySQL database to control mod_rewrite via PHP Load Balancing with Apache mod_jk (httpd/Tomcat) .php or .html extension? Morally Static Pages Compressing web pages sent out from server. Is it worth it? Simple but effective use of mod_rewrite (Apache httpd) Sharing the load with Apache httpd and perhaps Tomcat httpd.conf or .htaccess? This article Clustering, load balancing, mod_rewrite and mod_proxy To list a directory under httpd on a web server, or not? Using different URLs to navigate around a single script An unhelpful error message from Apache httpd Denial of Service ''attack'' Apache httpd to Tomcat - jk v proxy 2006 - Making business a pleasure Apache httpd - serving web documents from different directories Separating 'per instance' data from binaries and web sites Spotting a denial of service attack