Forum Moderators: phranque

Message Too Old, No Replies

Preserve referer on 301 redirect

         

dfresh4130

7:52 pm on Jan 26, 2015 (gmt 0)

10+ Year Member



In my project to set up a lot of 301 redirects for sunsetting one domain and redirecting all the specific URIs to another I have the requirement to create a cookie that contains the referrer for tracking purposes. Of course with a 301 you lose that. Are there any options or workarounds that someone can point me to to accomplish this? My googling hasn't turned up anything solid so far, but I'm sure this is something that comes up fairly often. Note that the 301s are on servers in the old.com domain and the cookie rule is on the servers in new.com. Below is a basic flow example:


old.com --> 301 to new.com and corresponding URI --> new.com sets cookie using the below rewrite --> code on new.com fires off correct logic if cookie is present


#Rewrite rule on new.com servers
SetEnvIfReferer old.com OLD_REFERER=$1
RewriteCond %{HTTP_REFERER} old.com [NC]
RewriteRule ^ - [CO=OLD_REDIRECTED:%{ENV:OLD_REFERER}:.new.com:1440:/]

penders

8:54 pm on Jan 26, 2015 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I'm not sure that I follow... The referer is normally preserved on a 301 redirect, that is of course if the user-agent is passing the referer in the first place?

The browser will then pass any previously set cookies for new.com when the browser is redirected there. (Although I would have thought you would just set the cookie when you see the referer at new.com?)

lucy24

10:19 pm on Jan 26, 2015 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Of course with a 301 you lose that.

In fact you don't: a referer is supposed to be preserved unchanged when there is an ordinary server-side redirect. It's in The Rules, though I'm ### if I can find the canonical passage :(

dfresh4130

12:18 am on Jan 28, 2015 (gmt 0)

10+ Year Member



I was working too hard and wasn't thinking about the way I was testing. I was going via direct links in my browser instead of clicking a link from another page. So there was no referrer to begin with in my testing. @_@