How do I write a .htaccess file the will redirect if you AREN'T coming from a specific website?
February 16, 2007 8:01 AM   Subscribe

How do I write a .htaccess file the will redirect if you AREN'T coming from a specific website?

I want to help my friend promote his services. He will provide a discount to those coming from a link I post on my website, that link will take them to a directory on his website where the prices are discounted. I want to write an htaccess file that makes it to where if you don't have my website or null in your referring header that it redirects you from his special discount directory to the root directory of his website. I've seen examples for blocking specific sites, but not allowing specific sites only.
posted by torpark to Computers & Internet (3 answers total) 1 user marked this as a favorite
Try something like this:
RewriteEngine on
RewriteCond %{HTTP_REFERER}	!
RewriteRule (.*)	[R]
You could also do this in JavaScript on the landing page by checking the document.referrer field. Keep in mind referrers can be forged, so don't count on this as for-realsies security.
posted by Loser at 9:00 AM on February 16, 2007

Referers can be forged, but they can also be blank (if coming from a bookmark, for example), or replaced with all 'X's (by some hardware firewalls), or be the IP address of your server, or be with/without the leading 'www.', or be the 'https:' variant, or any other working alias for the website.
posted by rjt at 10:11 AM on February 16, 2007

You could use a server-side or client-side programming on your special page that you want as your referrer on your friends site.

So on (the special page that sends people to your friend.) you could have it automatically send people who goto to and on you could set a post variable using curl and then check for that on
posted by mrapache at 6:14 AM on March 14, 2007 [1 favorite]

« Older How do I fix a nylon backpack zipper?   |   Masters in Journalism--Is it necessary? Newer »
This thread is closed to new comments.