3

I've setup some redirects on an Apache server. They look at bit like this:

Redirect /Name/register /login.html

My question is this... is there anyway to preserve the HTTP Referrer through this redirect? It would seem that by default, Apache discards the information. I would really like it if after the redirect was complete the referrer was say:

http://the.orginalurl.com/Name/register

Anyone if this is even possible? If not, thoughts on an alternative.

Many thanks, Neil

Neil Albrock
  • 1,035
  • 10
  • 16

5 Answers5

6

Redirect won't preserve the referrer because the browser is sent a 301 and a new address to open. From the manual:

The Redirect directive maps an old URL into a new one by asking the client to refetch the resource at the new location.

mod_rewrite and (I think) Alias can rewrite directly (i.e. without causing a browser redirect) and will preserve the referrer. With mod_rewrite, you can even add the referer as a GET parameter to your request, if you want to.

Pekka
  • 442,112
  • 142
  • 972
  • 1,088
  • Thanks for the clarification. I had a feeling this was the case, I guess it'll be the mod_rewrite route on this one. – Neil Albrock Jan 15 '10 at 16:25
1

It's a browser issue, not apache. There isn't much you can do about it. This is done to prevent certain security issues and referrer spam.

http://en.wikipedia.org/wiki/HTTP_referrer#Referrer_hiding

docwhat
  • 11,435
  • 6
  • 55
  • 54
  • This is not the OP's issue. The issue is that the referer (that is transmitted by the client) gets lost during the redirect. – Pekka Jan 15 '10 at 16:18
  • Which is what I said. Or is it that I didn't point out that the `Redirect` directive uses an HTTP redirect? Either way, your answer is better. – docwhat Jan 15 '10 at 16:46
  • Ahhh I see now. I thought you were not understanding the question, and referring to the fact that some browsers and security suites don't send a referer string at all. My apologies! – Pekka Jan 15 '10 at 17:07
1

You can always store the original referrer in a pipeline variable at the beginning of the request and just pull it from there instead.

kprobst
  • 16,165
  • 5
  • 32
  • 53
1

I created an alternative way that transfers the refferer through a 301 redirect. https://webmasters.stackexchange.com/questions/4665/

Community
  • 1
  • 1
Evgeny
  • 6,533
  • 5
  • 58
  • 64
0

I believe it all depends on how you write the rule. It can act as a "redirect" or a "rewrite" according to the flags you provide.

1. Redirect

302 will be sent to the browser, and it will initiate another request ( see Firebug with the "persist" option enabled ):

RewriteCond %{REQUEST_URI} !/index.html
RewriteRule ^(.*)$ /index.html [R=302,L]

2. Rewrite

browser does not initiate a 302 redirect because we don't send such header, but it will mask the content:

RewriteCond %{REQUEST_URI} !/index.html
RewriteRule ^(.*)$ /index.html [L]

In this option, if someone will access "page.html" he will see the content of "index.html" not "page.html" but the URL above will still show "page.html"

Good for maintenance page etc ... not sure about login pages ... but it's another option to think about.

The main difference between the "RewriteRule" vs "Alias" in my specific case, is that the rewrite can be set inside .htaccess while "Alias" does not ... so not always you can use Alias ...

Ricky Levi
  • 7,298
  • 1
  • 57
  • 65