Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Jul 2011
    Posts
    46
    Thanks
    12
    Thanked 0 Times in 0 Posts

    301 Redirect problem

    Hi, I had a page, team-info.php?team_id=48 for example and some of these pages have been indexed by google, I then decided to move team-info.php into a folder named team and use my .htaccess file to rewrite the links to team/48 meaning some of the results in google now link to an error page. I have tried to direct the old links to the new links but it doesn't seem to be working, here's my code:

    Rewrite rule that currently works to point dynamic link to a clean URL:

    RewriteRule ^team/([0-9]+)$ team/team-info.php?team_id=$1


    Rewrite rule to move the old dynamic link to the new one, that is not currently working:

    RewriteRule ^team-info.php?team_id=([0-9]+)$ team/$1 [R=301,L]

    If anyone can help me on this then I would be very grateful, i've been trying different solutions out for a while now and not getting anywhere, thanks.

  • #2
    New Coder
    Join Date
    Nov 2011
    Posts
    88
    Thanks
    4
    Thanked 26 Times in 26 Posts
    I think you issue is you can't match the question mark, instead you have to have a condition to match the querystring.

    I've not tested this heavily, but play with this:

    Code:
    RewriteCond %{REQUEST_URI} ^/team-info.php$
    RewriteCond %{QUERY_STRING} ^team_id=([0-9]+)$ 
    RewriteRule ^(.*)$ http://www.yoursite.tld/team/$1 [R=301,L]
    It may need some refinement, but it should get you close to where you are trying to go!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •