1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

htaccess question with referrer redirect

Discussion in 'Cloaking and Content Generators' started by avispasnegras, Feb 6, 2014.

  1. avispasnegras

    avispasnegras Newbie

    Joined:
    Nov 24, 2011
    Messages:
    28
    Likes Received:
    0
    Ok, the thing is that some site ( let's call it X ) refers to my site ( let's call it Y ). I would like that when the visitor from site X clicks on my link won't go to site Y but to another site I select ( let's call it Z ). So how can I make sure that when someone goes to X doesn't get directed to Y but to Z ?

    I've tried to enter this in httaccess but it just blocked my entire site to that page, even if I was just typing the address in the browser:

    RewriteEngine On
    RewriteCond %{HTTP_REFERER} !^http://sitex.com [NC]
    RewriteCond %{HTTP_REFERER} !^http://www.sitex.com [NC]
    RewriteRule ^ http://sitez.com/ [L,R]

    So the code above just blocked my site to sitez.com
     
  2. avispasnegras

    avispasnegras Newbie

    Joined:
    Nov 24, 2011
    Messages:
    28
    Likes Received:
    0
    anyone please help?
     
  3. solventnine

    solventnine Junior Member

    Joined:
    Dec 4, 2009
    Messages:
    113
    Likes Received:
    16
    You never mentioned whether you resolved the issue or not, and someone else in the future might benefit from this.

    From the Apache manual, mod_rewrite is for rewriting URLs, not redirecting. So you'd be better off scripting this than using .htaccess. An example follows.

    Code:
    <?php
         $incoming = $_SERVER['HTTP_REFERER'];
    
         if(stristr(strtolower($incoming), 'sitex.com') !== FALSE){
                header('Location: http://sitez.com');
         }
    ?>
    
    Otherwise, buy a cloaker.