Question: 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?

Answer: 
The variable for the referrer uses the common misspelling: `HTTP_REFERER`. See [this cheat-sheet](http://www.askapache.com/htaccess/mod_rewrite-variables-cheatsheet.html) 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.)
A tested method that works for me and transfers the refferer through a 301 redirect.
<https://webmasters.stackexchange.com/questions/4665/>