Forum Moderators: phranque

Message Too Old, No Replies

redirect GET data

redirect search query string

         

crosescu

12:12 am on Oct 31, 2006 (gmt 0)

10+ Year Member




I use a form like the one below to redirect the submitted search query string to the main page that handles the request.

<form method="get" action="/products/search">
</form>

below is what i am using to do the redirect which works but the query string stays the same as the original one even when I select a different option from one of the drop down boxes on the form and re-submit the form.

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /products/search\?state_id=([^&\ ]+)&city_id=([^&\ ]+)\ HTTP/
RewriteRule ^.*search$ /index.php?state_id=%1&city_id=%2 [L]

the redirect happens every time i submit the form but the query string does not get updated in the browser address bar. I don't have any other rules in my .htaccess file

Much Regards,
Chris

jdMorgan

12:35 am on Oct 31, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I don't know if it will fix your specific problem, which may be on the submission end rather than in the rewrite, but your rule can be simplified:

RewriteCond %{QUERY_STRING} ^state_id=[^&]+&city_id=[^&]+
RewriteRule search$ /index.php [L]

This is an internal rewrite, not a redirect, so the address bar of the browser will not be affected -- The 'mapping" of search?blah to /index?blah is done entirely within the server, and no handshaking with the browser is needed or desired.

Also, note that the original query string will be passed through unmodified, as was done (albeit the hard way) with the original code.

If "search" is *always* called with both state_id and city_id in that order, then you may delete the RewriteCond entirely. The function would then be simplified to rewriting any request for "search" in any directory to a request for index.php in the Web root directory, carrying any existing query string forward.

Jim

crosescu

2:56 am on Oct 31, 2006 (gmt 0)

10+ Year Member



thank you for your help Jim

the issue i have now is that if a user changes the order of the parameters in the query string (search?city_id=3&state_id=5) then the condition below will no longer be matched
RewriteCond %{QUERY_STRING} ^state_id=[^&]+&city_id=[^&]+
RewriteRule search$ /index.php [L]

Much Regards,
Chris

jd01

3:01 am on Oct 31, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I think Jim's question was, do you really need to match the query_string, or can you just pass any query_string to your index.php and let your php file do the processing?

If you do not need to know there is an exact match in the query_string, but need to know a query_string exists, you could use the condition:

RewriteCond %{QUERY_STRING} .

This would match any single character, so you know there is a query_string, and you can pass all information to your index.php for processing.

Justin

crosescu

3:07 am on Oct 31, 2006 (gmt 0)

10+ Year Member



Justin, that makes perfect sense. thank you