Go Back   CodingForums.com > :: Server side development > Apache configuration

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-04-2012, 08:14 PM   PM User | #1
lukep11a
New Coder

 
Join Date: Jul 2011
Posts: 46
Thanks: 12
Thanked 0 Times in 0 Posts
lukep11a is an unknown quantity at this point
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.
lukep11a is offline   Reply With Quote
Old 03-05-2012, 06:27 AM   PM User | #2
leslie.jones
New Coder

 
Join Date: Nov 2011
Posts: 88
Thanks: 4
Thanked 26 Times in 26 Posts
leslie.jones is an unknown quantity at this point
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!
leslie.jones is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:01 PM.


Advertisement
Log in to turn off these ads.