Forum Moderators: phranque

Message Too Old, No Replies

Another rewrite question

apache rewrite url parameters

         

Gissit

9:47 pm on Dec 12, 2007 (gmt 0)

10+ Year Member



Hi
I am fighting a little with what should be a really simple task

I want to rewrite mysite.com/example.php?page=1 to stuff.php?parent_id=50&page=1

What I have right now is:

RewriteRule example.php(\?*)(.*) stuff.php?parent_id=50&$1

and this works fine for mysite.com/example.php to stuff.php?parent_id=50 but does not work with the page parameter.

jdMorgan

11:11 pm on Dec 12, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



RewriteRule cannot 'see' query strings, because they are data attached to a URL, and not part of the URL itself. In other words, the query string data has to be passed to the resource at that URL and is therefore not part of the Resource Location.

Therefore, you must check the query string separately:


RewriteCond %{HTTP_QUERY_STRING} ^(page=[^&]+)$
RewriteRule ^example\.php$ /stuff.php?parent_id=50&%1 [L]

This may not be exactly what you need, as it isn't clear "how variable" your variables are.

Jim