I want to only allow access to a page on my website by url referral only. eg, the file to be displayed is: www.mydomain.com/showpage.html I dont want people to be able to type the exact url, i only want the page to be viewed by referral from eg: www.mydomain.com/main.html Hope that makes sense, if i could re-direct people who try and access the url without referral that would be great !! Hope someone can help !
Try the following htaccess code to redirect all visitors without a referer to another page Options +FollowSymLinks RewriteEngine on RewriteCond %{HTTP_REFERER} ^$ RewriteRule (.*) http://www.yourdomain.com/path/to/redirect/ Code (markup): On the other hand, if you want only visitors referred by some particular domain/url to access a page try Options +FollowSymLinks RewriteEngine on RewriteCond %{HTTP_REFERER} !^http://(www\.)?allowed-domain1.com [NC] RewriteCond %{HTTP_REFERER} !^http://(www\.)?allowed-domain2.com/allowed/url/ [NC] RewriteCond %{HTTP_REFERER} !^http://(www\.)?allowed-domain3.com/allowed/page.html[NC] RewriteRule (.*) http://www.yourdomain.com/path/to/redirect/ Code (markup): This allows visitors referred by the above three domains/urls to access the contents. Others are redirected
Eg. I have the page http://www.bluepage.com/videos/index.html I only want people to be able to see that page who have came from http://www.redpage.com any other traffic i want to re-direct to http://www.greenpage.com
Try this code. Put it in http://www.bluepage.com/videos/ Options +FollowSymLinks RewriteEngine on RewriteCond %{HTTP_REFERER} !^http://(www\.)?redpage.com [NC] RewriteRule (.*) http://www.greenpage.com [NC,R,L] Code (markup): Change the last line to RewriteRule (.*)/index.html http://www.greenpage.com [NC,R,L] Code (markup): to redirect the visitors to http://www.bluepage.com/videos/index.html only. Or else every pages in the directory gets affected.
Use PHP, HTTP_REFERER - http://php.net/reserved.variables <?php if ($_SERVER['HTTP_REFERER'] == 'http://www.redpage.com') { # welcome buddy! } else { # hey, where do you think you are going?!? } ?> PHP: Please note that, as stated here http://php.net/reserved.variables: "The address of the page (if any) which referred the user agent to the current page. This is set by the user agent. Not all user agents will set this, and some provide the ability to modify HTTP_REFERER as a feature. In short, it cannot really be trusted."
Thanks for all the info i will give it a try, another question. Could i have the content displayed on my website dependant upon the reffer url ?
Of course - I don't know if you are using PHP, but using the same trick above you could do something like: <?php if ($_SERVER['HTTP_REFERER'] == 'http://www.redpage.com') { include 'redpage.html'; } elseif ($_SERVER['HTTP_REFERER'] == 'http://www.yellowpage.com') { include 'yellowpage.html'; } else { # all other referrers } ?> PHP: HTH, cheers!
Possible with htaccess too Suppose the file for referrals from redpages.com are in yourdomain.com/redpages/ and those for bluepages.com are in the directory bluepage then use RewriteCond %{HTTP_REFERER} ^http://(www\.)?redpage.com [NC] RewriteRule (.*) redpages/$1 [NC,R,L] RewriteCond %{HTTP_REFERER} ^http://(www\.)?bluepage.com [NC] RewriteRule (.*) bluepages/$1 [NC,R,L] Code (markup): Here any request for a file will be mapped to the directory corresponding to that referer. If you are using a server side script like php, then I would recommend picouli's method over this.
Thanks for the advice... I’m getting closer to what I want to do here!! The file I will be using will be called index.php The code above by picouli works OK...BUT…What I would like to do is have all my content in the index file and include a different stylesheets depending on the refferer.
If you make your layout dependent on CSS then in index.php where the HTML head tags are, inbetween them put: <?php if ($_SERVER['HTTP_REFERER'] == 'http://www.redpage.com') { <link href="redstyle.css" rel="stylesheet" type="text/css" /> } else { <link href="yellowstyle.css" rel="stylesheet" type="text/css" /> } ?> PHP: And have the 2 CSS files display a different layout or style for your site.