0

There is lots of info on redirection based on referrer, but this is not what is requested.

I need the target website to see the url (or at least the domain) from where the visitor was redirected. Usually, if the user clicks on a link (domain1) to a webside that redirects the user via htaccess (domain2) to an other website (domain3), then the server that domain 3 sits on loggs the website where the link was clicked (domain1) as referrer. I need the redirecting website (domain2) to be passed as referrer.

A usual redirect would be:

RewriteEngine on 
RewriteRule ^(.*)$ http://www.newdomain.com/$1 [R=301,L]
Rand
  • 13
  • 3
  • Take a look at the header module for the apache http server. It allows to set headers. It also can be within distributed configuration files. So I would expect that you can set a referrer header with the value of the received referred. http://httpd.apache.org/docs/current/mod/mod_headers.html#header – arkascha Jun 25 '20 at 19:30
  • @arkascha not sure how that could help? The `Header` directive sets response headers, but the Referer is a request header. – CBroe Jun 26 '20 at 07:07
  • There’s a couple of questions dealing with this already, such as https://stackoverflow.com/questions/4043196/get-http-referrer-on-redirection (which explicitly says this wasn’t possible; but this is quite old, I did not explicitly test if things have changed since then.) – CBroe Jun 26 '20 at 07:10
  • Maybe doing the redirect on the client side could help? Try and have domain2 respond with an actual HTML document, that redirects the user by using a meta refresh or JavaScript, and see what referrer value you get then on domain3. – CBroe Jun 26 '20 at 07:11
  • JS and refresh work. But needed htaccess here. – Rand Jun 26 '20 at 17:33

1 Answers1

0

It is not really possible, but even if it was, the client (browser) may simply decide to not pass the referrer info as it becomes more common with the advancement of privacy tools.

I'm adding a ?referrer=whatever (or &referrer=whatever if it already has a query string) to the end of my redirect target URLs in .htaccess, so it can be reliably detected on the target site both on server and client side.

Pro tip: Don't forget to add referrer to the "Exclude URL Query Parameters" in your Google Analytics or other places where the same URL counted as different would be an issue.

Bence Szalai
  • 768
  • 8
  • 20