Welcome to WebmasterWorld Guest from 18.206.48.142

Forum Moderators: Ocean10000 & phranque

Message Too Old, No Replies

How to keep referrer?

when redirecting to other domain

     
1:13 pm on Jun 25, 2004 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Aug 30, 2002
posts:1377
votes: 0


Hi all,

I need some help with a redirecting/referrer issue. If I do a 301 redirect (or any type other redirect) to a page within a domain I still see the original referrer in my logs for the new page.

When I redirect to an external site the referrer gets lost. How do I solve this?

I know virtually nothing about servers and technicalities so please keep it as simple as possible. If this has been covered I didn't recognise it as the same problem so excuse in advance. I don't even know if this is the right forum :)

The site is running on Apache/1.3.31 with cpanel.

Thanks!

2:21 pm on June 25, 2004 (gmt 0)

Senior Member

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 31, 2002
posts:25430
votes: 0


HitProf,

You could attach the original referrer to the new URL as a query string. It won't be 'pretty' in your new domain's logs, but at least the info will be available.

This may require the use of mod_rewrite to do the redirection, rather than mod_alias.

For example, the following mod_rewrite snippet will redirect all requests to www.newdomain.com, and attach the original referer (if available) as a query string parameter named "ref":


RewriteCond %{HTTP_REFERER} (.*)
RewriteRule (.*) http://www.newdomain.com/$1?ref=%1 [QSA,R=301,L]

This is only an example, as I have no idea whether you desire to redirect all URLs or just some of them, or whether you currently use query strings and my use of the parameter "ref" conflicts with one you have already assigned. As shown, the code is intended for use in .htaccess in the root directory of your 'old' domain.

Refs:
Apache mod_rewrite documentation [httpd.apache.org]
Apache URL Rewriting Guide [httpd.apache.org]
Regular Expressions Tutorial [etext.lib.virginia.edu]

Jim

3:28 pm on June 25, 2004 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Aug 30, 2002
posts:1377
votes: 0


Hi Jim,

Thanks very much for you suggestion.

I already use a tracking code behind the url like you mention.

For this particular situation that doesn't work however because this particular client has no access to his referrer logs. He's stuck with a simple counter and can only see "referers" that are recognised by this counter. (It's for a banner ad to a hobby site).

And on my side I'm stuck with cpanel, no access to unix command lines :)

So I hope you have another type of solution? Is this normal or a glitch on the server side?

4:08 pm on June 25, 2004 (gmt 0)

Senior Member

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 31, 2002
posts:25430
votes: 0


> So I hope you have another type of solution?

You could try using a script to do the redirects; perhaps you can force the referrer by having the script write the http_referer header. This is not my area, but it might be possible.

> Is this normal or a glitch on the server side?

Completely normal. The http_referer gives information on the previous page. In the case of a redirect, the previous page is the redirecting page, so the original referrer is lost.

Jim

11:33 am on June 28, 2004 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Aug 30, 2002
posts:1377
votes: 0


Word from host: server side firewall... We've unlocked it for a specific url and it works fine now. Showing the originating page as referer.

JM:

The http_referer gives information on the previous page. In the case of a redirect, the previous page is the redirecting page, so the original referrer is lost.

If this were 100% true it couldn't work within the site either...
301 must be able to recall the original referer somewhere.

Thanks, learned something new again :)

1:55 pm on June 28, 2004 (gmt 0)

Preferred Member

10+ Year Member

joined:May 4, 2004
posts:525
votes: 0


The referer header might be screwed only if you do multiple redirects, for example see this scenario:
You had a page called dummy.html on your website, but you renamed it to dummy.php because of some reason. To keep the stability of the links on the website you make a redirection in the apache to redirect all requests for dummy.html to dummy.php.
Assume you have the following links in index.html.
If you have a link for dummy.php, the referer header will be index.html, so you have the correct header. But if your link is pointing to dummy.html (so the request is being redirected to dummy.php), then the referer header might become dummy.html, not index.html. I think this is highly depending on the browser being used, because in a case of redirect the browser need to make a new request for the resource marked in the redirect response (dummy.php in our case), so the referer can by any of these pages, I don't think there's any recommendation about this in the HTTP 1.1 RFC.

Anyway, the header should not get lost, only because you do an external redirect.

 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members