Redirect use if come from domain x

Status
Not open for further replies.

djflakf1

Active Member
60
2012
6
30
Hello i need help with this...

i want to deny access to my website to the user if they come from a site example....

in the page www.web1.com there is a link

PLEASE CLICK HERE ( and this link is for my site www.web2.com )

well i want to deny access or redirected to the user if they come from the www.web1.com

is posible?
 
5 comments
You can use .htaccess redirect based on Referrer. Add this in your .htaccess file:
PHP:
RewriteCond %{http_referer} ^http://([^.]+\.)*(web1)\.com
RewriteRule .* die.html
In the above code, when someone comes to your website (web2.com) from a webs1.com link, then he would be redirected to die.html on your server
 
Last edited:
i did try with that but is not working :( ... somebody give me this code

http://foros.emprear.com/javascript/referer.php

that code show tha referee and put the name of the site ... but this guy said me that if i put a conditional for redirectr if the user come from a especific site is posible but the problem is that i don't know how put that conditional ... can you help me?
 
Those are two alternative ways of getting the referer. For a PHP check, add this conditional check to the top of the file:
PHP:
<?php 
if (strpos($_SERVER['HTTP_REFERER'], 'www.web1.com') !== false) {
  header('Location: http://www.web2.com/die.html');
}
?>
This will check if the referer URL contains www.web1.com and redirects to http://www.web2.com/die.html if so.
 
The example above may not be working because the strpos function is looking for such a long string and getting that whole match is problematic. So instead of putting the whole URL (http://www.eventoshq.com), use this instead eventoshq.com. This will check whether the user came from that website, no matter if it had www. or not.

Since $_SERVER['HTTP_REFERER'] is user input, it's not to be trusted, but there is no other way to achieve this.

PHP:
<?php 
if (strpos($_SERVER['HTTP_REFERER'], 'eventoshq.com') !== false) 
{
       header('Location: http://www.google.com');
}
?>
 
Status
Not open for further replies.
Back
Top