Forum Moderators: phranque

Message Too Old, No Replies

Store refid then 301redirect to remove query string?

         

jamsuet

2:30 pm on Apr 9, 2009 (gmt 0)

10+ Year Member



I'm completely stuck with this (beginner!) but have seen other sites doing it so am hoping someone out there knows how it works..

I need to capture an id within a query string and somehow store it before it gets removed from the URL.

eg.
External URL1: www.example.com/?refid=999
External URL2: www.example.com/page/content/?refid=999

So I have this in htaccess which removes the query string from both of the above (and any other) URL:

RewriteCond %{QUERY_STRING} ^refid=
RewriteRule ^(.*)$ /$1? [R=301,L]

The problem is I can't see how to store the 'refid' before it gets redirected. Currently I capture it in a session which is triggered once the PHP page has loaded, which won't be possible if it gets removed before the session is created, right?

Am I looking at this wrong? Any ideas how this is done?

Now I'm at the end of writing this I'm not even sure this is the right forum! Any help appreciated.

jdMorgan

3:39 pm on Apr 9, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you want to carry any information from one HTTP request to another, you'll need to put it into a client-side cookie; A redirect terminates the current HTTP transaction and asks the client (browser) to start a new one. Because HTTP is a stateless protocol, all information about the previous HTTP request is lost unless the client provides it as a cookie or a query parameter. And since your intent is to remove the query string, that leaves only a cookie as a possible solution.

Jim

jamsuet

9:12 pm on Apr 9, 2009 (gmt 0)

10+ Year Member



Thanks for the explanation, that makes perfect sense and I'd completely overlooked it being the only solution.