.htaccess 301 Redirect Issue

Discussion in 'Apache' started by jason360, Jan 17, 2013.

  1. #1
    Hey guys,

    I am a .htaccess newbie having a problem with a 301 redirect. I am trying to do a 301 redirect that has a PHP variable, but the redirect is not clean and causing some seo google problems.

    I am trying to redirect the following:

    From:

    http://www.example.com/dog/cat/index.php?pid=13

    To:

    http://www.example.com




    I have been using this redirect:

    RedirectMatch 301 /dog/cat/ http://www.example.com

    That redirectmatch is producing the following result which is not clean and problematic:

    http://www.example.com/?pid=index.php



    Any ideas how to fix this?

    Thanks

    Jason
     
    jason360, Jan 17, 2013 IP
  2. zacharooni

    zacharooni Well-Known Member

    Messages:
    346
    Likes Received:
    20
    Best Answers:
    4
    Trophy Points:
    120
    #2
    Two possible solutions for you:

    Use RedirectMatch's capture group feature:



    RedirectMatch /dog/cat/index\.php\?pid=(\d+)$ http://www.example.com/?pid=$1
    Code (markup):


    Use PHP to perform the redirect:

    <?PHP
    if ((int) $_GET['pid'] == 13)
    {
    die(header("Location: http://www.example.com/", 301));
    }
    ?>
    PHP:
     
    zacharooni, Jan 20, 2013 IP
  3. jason360

    jason360 Peon

    Messages:
    7
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    3
    #3
    Thanks Zach! That helped!
     
    jason360, Jan 22, 2013 IP
  4. tnhcatherine

    tnhcatherine Peon

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #4
    Thanks for the helpful information zach. Really appreciate your efforts.
     
    tnhcatherine, Feb 13, 2013 IP