Forum Moderators: phranque

Message Too Old, No Replies

RewriteRule and form method GET

Adding variables if variables already exist

         

twist

9:16 pm on Jan 28, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I posted a couple times on webmasterworld asking how to accomplish something but never recieved an easy way to accomplish what I was trying to do. Probably my fault for not being more descriptive. Anyway, after reading older posts here I found the solution and felt I should share it with anyone else that might be trying to accomplish the same thing.

I was trying to setup a search using the GET method like so,

example.com/search?v1=1&v2=1&v3=1

The problem was that all my files are inside of a 'deny from all' folder and the only access to this folder is through one php file. So by default all pages on my website are referenced this way in .htaccess

RewriteRule ^homepage$ /script.php?page=homepage [L]
RewriteRule ^question$ /script.php?page=question [L]
RewriteRule ^search$ /script.php?page=search [L]
and so on...

The problem I ran into was trying to use the GET method because it would automatically append a '?' causing my searches to fail. The solution was using the QSA (i think it stands for query search append) like so,

RewriteRule ^search$ /script.php?page=search [QSA]

Now when the GET method appends the variables onto the address. Thanks webmasterworld, would be lost without this place.

jdMorgan

9:33 pm on Jan 28, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes, the [QSA] flag (query string append) overrides mod_rewrite's default behaviour, which is to overwrite the original query string if a new one (or even just a single "?") appears in the RewriteRule's substitution URL.

Jim