Forum Moderators: phranque

Message Too Old, No Replies

.htaccess referral redirect?

www.theirdomain.com link to www.mydomain.com redirect to specific webpage

         

Webracadabra

6:26 pm on Sep 18, 2006 (gmt 0)

10+ Year Member



I'm very new using .htaccess and need help. How would I create a redirect based on a referral? Currently, I have a business partner website linking to my webiste's root directory (not to a specific page). I want to make a redirect from their website so a specific directory and webpage on my site.

Their link:
from www.partnerwebsite.com/somepage.html links to www.mywebsite.com/

I need to redirect that link so anyone from www.partnerwebsite.com/somepage.html will land on www.mywebsite.com/other_directory/specific_page.shtml.

I've played around with a bunch of .htaccess RewriteCond and RewriteRule, but no success. Last attempt was:
RewriteEngine On
RewriteCond %{HTTP_REFERER} ^(www\.)?partnerwebsite\.com
RewriteCond %{QUERY_STRING}!.
RewriteRule ^(www\.)?mywebsite\.com$ other_directory/specific_page.shtml [NC,L]

Thanks for any help on this!
JC

jdMorgan

1:08 am on Sep 19, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Please define "no success" as otherwise, there may be a hundred possibilities...

Jim

Webracadabra

12:26 am on Sep 29, 2006 (gmt 0)

10+ Year Member



Basically, no success means I've tried multiple lines of code (most of which I don't know what it means) and no redirect occurs when I test.

How do I do redirect based on a referral?

Their link:
from www.partnerwebsite.com/somepage.html links to www.mywebsite.com/

I don't want them landing on my index page, so I want:
www.partnerwebsite.com/somepage.html links to www.mywebsite.com/
and redirected (using .htaccess) to www.mywebsite.com/somedirectory/somepage.html

Suggestions on .htaccess coding to do this?

jdMorgan

12:38 am on Sep 29, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This should work better:

RewriteEngine on
RewriteCond %{HTTP_REFERER} ^http://(www\.)?partnerwebsite\.com
RewriteRule ^$ /other_directory/specific_page.shtml [L]

In no case does the URL-path examined by RewriteRule contain the hostname. It contains the local URL-path only. In the case of a request for the domain root document -- the home page "/" -- the local URL-path as seen by a RewriteRule in an .htaccess file in that directory will be blank.

There is no need to check the QUERY_STRING, since your problem description does not mention it.

For more information, see the documents cited in our forum charter [webmasterworld.com] and the tutorials in the Apache forum section of the WebmasterWorld library [webmasterworld.com].

Jim