301 redirect and add pass custom referring link

Discuss practical ways rearrange URLs using mod_rewrite.

301 redirect and add pass custom referring link

Postby hucklberry » Thu Sep 04, 2008 8:58 am

I am currently using StatCounter to monitor traffic for my domains. One domain is 301 redirected using the following htaccess code:

Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} !^redirecteddomain\.com [NC]
RewriteRule (.*) http://targetdomain.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^redirecteddomain\.com [NC]
RewriteRule (.*) http://targetdomain.com/$1 [R=301,L]

When StatCounter logs a hit from the redirected domain it shows as "No referring link".

I would like to have the log show "redirecteddomain.com" as the referring link to monitor which redirected domain is providing traffic when redirecting multiple domains.

Is there a way to accomplish this using htaccess?

Any help is much appreciated.
hucklberry
 
Posts: 3
Joined: Thu Sep 04, 2008 8:44 am

Postby richardk » Thu Sep 04, 2008 10:02 am

I don't think this is possible. StatCounter is almost certainly using the HTTP_REFERER header/variable to find out the referring page. Mod_rewrite cannot set this header.

You could set a query string variable
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteRule ^(.*)$ http://targetdomain.com/$1?referring_domain=%{HTTP_HOST} [QSA,R=301,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby hucklberry » Thu Sep 04, 2008 10:44 am

Thank you ... this will work just fine for me.

Will search engines attempt to index the result "targetdoamin.com/?referring_domain=referringdomain.com" or is everything after the ? ignored.

Thanks for helping.
hucklberry
 
Posts: 3
Joined: Thu Sep 04, 2008 8:44 am

Postby richardk » Thu Sep 04, 2008 12:52 pm

No, it is not ignored. It is not an ideal solution.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby hucklberry » Thu Sep 04, 2008 2:32 pm

What would an ideal solution look like? I assume it would be outside of using htaccess?
I am new to website development and domain management and your thoughts are very much appreciated.
hucklberry
 
Posts: 3
Joined: Thu Sep 04, 2008 8:44 am

Postby richardk » Fri Sep 05, 2008 8:50 am

I think the only reliable solution would be to log it before the redirect. You could use the server's access log.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am


Return to Friendly URLs with Mod_Rewrite

Who is online

Users browsing this forum: Google [Bot] and 26 guests

cron