Redirect some users but not all

by Trivum
9 replies
Can someone tell me if there's a simple way to redirect certain users to a different page with some javascript or php or something else easy to implement.

What I'd like to do is the following:

Let's say my site is mysite.com

If the user comes to mysite.com from MyFriendsSite.com, I'd like to redirect him to mysite.com/myfriend.html.

If the user comes to mysite from Google or anywhere else, I'd like him to remain on the mysite.com homepage.

Thanks for any suggestions.
#redirect #users
  • Profile picture of the author Mohsin Rasool
    Hi,

    It can be done in PHP, put this code at the top most of the index page.
    Nothing should be placed before this code on the top of the page otherwise
    it will give you error.


    Let me know if this works for you or not.

    Best Regards,
    Mohsin Rasool
    {{ DiscussionBoard.errors[2187382].message }}
  • Profile picture of the author Mohsin Rasool
    Hi,
    I tried to post the PHP code but it would not allow me to post..

    so i have posted the code in this post i made for you:
    Redirect to Different Page for Different Refferer Sites at WarMarks Blog

    Let me know if this work or not for you,
    Mohsin
    {{ DiscussionBoard.errors[2187408].message }}
    • Profile picture of the author Trivum
      Hi,

      Thanks for the reply. I've been trying to test it out, but I can't get it to work. I've done a few different tests. Here's one.

      I made 3 pages -

      mysite.com/page1.htm
      mysite.com/page2.htm
      mysite.com/page3.htm

      Then I did the following:

      mysite.com/page1.htm -- I put a link to mysite.com/page2

      mysite.com/page2.htm -- I put your code in with the following for this section:

      preg_match("/mysite.com/page1.htm",$referrer)

      and then this to redirect it to page3.htm...

      ('Location: mysite.com/page3.htm')

      and then this to stay on the page if not from page1....

      else {

      header('Location: mysite.com/page2.htm');


      Am I doing that right? I've also done the same with a different domain as the original source (i.e. my2ndsite.com links to mysite.com/page2.htm with a redirect to mysite.com/page3.htm)

      Thanks for any more help.
      {{ DiscussionBoard.errors[2189553].message }}
  • Profile picture of the author kiopa
    Banned
    Put a "i" at the end of the last "/" in the preg_match function. For example, instead of having:

    if (preg_match(“/YourFriendSite.com/”,$referrer)

    Have:

    if (preg_match(“/YourFriendSite.com/i”,$referrer)

    Notice the extra "i" in there. If there's still a chance it doesn't work, you may have referers turned off in your browser. Try a new browser in that case.
    {{ DiscussionBoard.errors[2189865].message }}
    • Profile picture of the author Trivum
      Thanks, but it's still not working for me. I tried three different browsers.
      {{ DiscussionBoard.errors[2190003].message }}
  • Profile picture of the author links900
    try it with IP address.Some time error occurs due to differnt convention used for domain name
    Signature
    A Free Soul !!!!!!!
    {{ DiscussionBoard.errors[2209726].message }}
  • Profile picture of the author Mohsin Rasool
    Sorry for not checking this thread out before... Have this worked for you or not?
    let me know if you still need this fix... I will try to post alternative or send you actual code. You can pm me actual page urls and I will try to write code for that see if it works so i send you actual code....

    Best Regards,
    Mohsin
    {{ DiscussionBoard.errors[2217296].message }}
  • Profile picture of the author Trivum
    Mohsin - Thanks for checking in. When I couldn't get a fix, I decided to abandon my plan. If you have a quick alternative, I would like to check it out.

    ~ Thanks
    {{ DiscussionBoard.errors[2218581].message }}
  • Profile picture of the author Mohsin Rasool
    Hi Buddy,

    Let's figure it out.

    Well i tested the following and it worked....
    Try it out and let me know if it works for you...

    http://fitvre.com/trivum/

    Ok checkout above link... if you click it...
    it does this:

    1. If referrer is Warrior Forum... warriorforum.com
    it will redirect to you to Google.com

    2. If it is not... it does nothing..and show the acutal page content!!

    I think that is what you are trying to do...

    Now replace Warrior Forum with your Friends domain... like yourfriendsdomain.com

    and replace google.com with your special page url you want to send your friend's
    referrals...

    Regards,
    Mohsin
    PS. code on fitvre.com/trivum page is attached....
    the code in this attache text file should be put on your index.php file where
    you want this magic redirect happen.

    Please update me how it goes....
    {{ DiscussionBoard.errors[2220289].message }}

Trending Topics