views:

578

answers:

3

In my .htaccess file I have a set of rules as follows:

RewriteRule ^dir/page1$ /bleh/docs/?id=12 [L,QSA]
RewriteRule ^dir/page2$ /bleh/docs/?id=13 [L,QSA]
RewriteRule ^dir/page3$ /bleh/docs/?id=14 [L,QSA]

Sometimes one of these rules may be accessed via a redirect from another site (referer). I would like to be able to append the referrer to the query string like this:

RewriteRule ^dir/page2$ /bleh/docs/?id=13&ref=%{HTTP_REFERER} [L,QSA]

However this does not seem to work.

What am I doing wrong?

+1  A: 

The variable for the referrer uses the common misspelling: HTTP_REFERER. See this cheat-sheet for some more variable names.

As far as I know, a rewritten URL won't remove the original Referer header though, so you should still be able to fetch it from your code without passing it as a query string parameter (provided it gives you access to the HTTP variables.)

Blixt
+2  A: 

If you're spelling it HTTP_REFERER (this is unclear due to edits), you're doing it correctly. If it isn't working at that point, it's because the referer isn't being supplied. (Which there are any number of reasons for; supplying it is at the browser's discretion.)

chaos