Redirect if traffic comes from a certain source

5 replies
Hi,
is there a way, possibly via Wordpress plugin or by changing the wordpress .htaccess file, to redirect traffic that comes from a certain website to another URL ?

For example, if traffic is coming from Facebook to mysite.com, people can see mysite.com . But if traffic comes from Twitter, people will be sent to anothersite.com

It would be extremely helpful

Thank you
#redirect #source #traffic
  • Profile picture of the author tantykimi
    I believe it's somehow possible if you're experienced with programming, but I'm not too sure. I'll take a look and see if I can find anything for you.
    {{ DiscussionBoard.errors[9176015].message }}
    • Profile picture of the author Brandon Tanner
      Pretty simple job with a couple lines of PHP...

      <?php
      $ref = $_SERVER['HTTP_REFERER'];
      if (preg_match("/twitter.com/", $ref)) { header("http://www.anothersite.com"); }
      ?>


      ^ The text in red is the referring URL string that you want to match (don't use "http" or "www" here -- just use "domain.com" with a forward slash at the beginning and end).

      The blue text is the website you want to forward those visitors to. DO start this with "http://".

      You can use as many conditional statements as you need to redirect from/to different URL's. Just be sure to put this code at the very beginning of the page, before any HTML code. Also, the page needs to have a PHP extension (ie index.php).

      Redirecting based on referrer is not 100% reliable, due to possible browser settings, firewalls, etc. But it should work fine for 95% + of your visitors.
      Signature

      {{ DiscussionBoard.errors[9176795].message }}
      • Profile picture of the author geraldakim
        Hi Brandon Tanner,

        Thanks for your information.May i know where is this code located.I need to know.Waiting for your response.


        Thanks
        Geraldakim
        {{ DiscussionBoard.errors[9188431].message }}
  • Profile picture of the author 2WDHost
    Hi.

    Did you check the following plugin: WordPress › Redirection « WordPress Plugins ?
    {{ DiscussionBoard.errors[9176893].message }}
  • Profile picture of the author FlamingWolf
    Thank you all for your replies

    Originally Posted by Brandon Tanner View Post

    Pretty simple job with a couple lines of PHP...

    <?php
    $ref = $_SERVER['HTTP_REFERER'];
    if (preg_match("/twitter.com/", $ref)) { header("http://www.anothersite.com"); }
    ?>


    ^ The text in red is the referring URL string that you want to match (don't use "http" or "www" here -- just use "domain.com" with a forward slash at the beginning and end).

    The blue text is the website you want to forward those visitors to. DO start this with "http://".

    You can use as many conditional statements as you need to redirect from/to different URL's. Just be sure to put this code at the very beginning of the page, before any HTML code. Also, the page needs to have a PHP extension (ie index.php).

    Redirecting based on referrer is not 100% reliable, due to possible browser settings, firewalls, etc. But it should work fine for 95% + of your visitors.
    Thank you for your suggestion. Unfortunately it doesn't seem to be working ( it probably conflicts with part of Wordpress code. Once I put that code, it always redirects to the blue URL. I tried with 3 different browsers, all get the same issue

    Originally Posted by 2WDHost View Post

    Hi.

    Did you check the following plugin: WordPress › Redirection « WordPress Plugins ?
    Unfortunately is not compatible with Wordpress 3.9
    {{ DiscussionBoard.errors[9181651].message }}

Trending Topics