Forum Moderators: phranque

Message Too Old, No Replies

Preserving query string with mod rewrite

how to 'add' the query string on after a mod_rewrite

         

craig_oeuk

2:22 pm on Jul 2, 2008 (gmt 0)

10+ Year Member



Hello,

I have a problem with mod_rewrite. I need to rewrite this:

/support/documentation/?var=value

To this:

/support.php?page=documentation&var=value

I'm obviously approaching this the wrong way, but a couple of things I've tried are:

RewriteCond %{REQUEST_URI} ^support/documentation/(.+)$
RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule ^(.*)$ /support/documentation/$1?%1 [L] fhshsfj

And

RewriteRule ^support/documentation/\?(.+)$ /support.php?page=documentation&$1

Can anyone point me in the right direction?

Thanks in advance

jdMorgan

7:42 pm on Jul 2, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Two methods, depending on whether it matters what order the name/value pairs end up in.

Simple method:


RewriteCond %{QUERY_STRING} !page=
RewriteRule ^support/documentation/$ /support.php?page=documentation [QSA,L]

More complex method to enforce name/value pair order:

RewriteCond %{QUERY_STRING} !page=
RewriteCond %{QUERY_STRING} (var=[^&]+)
RewriteRule ^support/documentation/$ /support.php?page=documentation&%1 [L]

See [QSA] flag (query string append) in the mod_rewrite documentation.

In both cases above, the first RewriteCond prevents an 'infinite' rewriting loop in .htaccess.

Jim