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 (4 answers total) 1 user marked this as a favorite
 
From here, you could modify it to something like:

SetEnvIfNoCase Referer "^http://www.your-domain-name-here.com/" locally_linked=1
Order Allow,Deny
Allow from env=locally_linked

You may also want to consider using .htaccess password protection with an .htpasswd file. You could just provide the username and password on your site and then protect the entire directory on his site with that same combination. If for some reason people are blocking referers, or copy and paste the link from your site to his, they'd still be able to get to the special area.
posted by odinsdream at 8:50 AM on February 16, 2007


Try something like this:
RewriteEngine on
RewriteCond %{HTTP_REFERER}	!yourreferrer.com
RewriteRule (.*)	http://thesiteroot.com/	[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 yourpage.com/dream (the special page that sends people to your friend.) you could have it automatically send people who goto yourpage.com/dream to friendspage.com/reffered and on yourpage.com/dream you could set a post variable using curl and then check for that on friendspage.com/referred
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.