views:

58

answers:

1

I have the following problem: I use a script that saves the referer URL. I want this URL to one of my own URLs. So let's say a users access the page http://example.com/page1 I want to rewrite that URL to http://example.com/page2 and safe the referer on that page.

I don't want to do that with a PHP script as otherwise I would have to extend that script each time I want to track a new referer. I already tried these rewrite rules:

RewriteRule ^page1$ /page2 [R=301,QSA,NC]
RewriteRule ^page1$ /page2 [L,R=301,QSA,NC]

The rewrite works, but the request parameter referer is missing. Do I have to use another stauts code than 301 or is there any other error in my rewrite. Is it even possible to set the referer in a rewrite rule?

+1  A: 

Using the R flag causes an external redirect. If you just want an internal rewrite, omit the R flag:

RewriteRule ^page1$ /page2 [QSA,NC]
Gumbo
But that wouldn't set the HTTP_REFERER or am I wrong? I want page1 to appear on page2 as the value of HTTP_REFERER. Is this even possible with a rewrite rule?
Kau-Boy
@Kau-Boy: Doing an internal rewrite doesn’t change the HTTP request. The request is just rewritten internally to another URI.
Gumbo
So in short, it is not possible without a PHP script in the middle that does a header redirect to change/set the HTTP_REFERER? When that's how I have to do it, it's all right. Just wanted to know if it works with rewrite rules. (If you add a "doesn't work that way to your answer, I'll accept it).
Kau-Boy
@Kau-Boy: The client sets that header field, not the server.
Gumbo
So the answer it: IT'S NOT POSSIBLE! Thanks for your answer making that clear!
Kau-Boy