301 Redirect Help

Hello everyone,

I have several URLs that I need to manually AND automatically redirect, but am not sure how what code to add in the .htaccess file.

For example:

http://www.website.com/forumdisplay.php?f=5 should redirect to http://www.website.com/forums/5
http://www.website.com/forumdisplay.php?f=6 should redirect to [URL=“http://www.thecloudgamer.com/forums/forumdisplay.php/5-News-Articles”]http://www.website.com/forums/6

HOWEVER,

Every other # that is NOT 5 and 6 (i.e. http://www.website.com/forumdisplay.php?f=9) should redirect to [URL=“http://www.thecloudgamer.com/forums”]http://www.website.com/forums

Thanks very much.

RewriteCond %{QUERY_STRING} f=([56])$
RewriteRule forumdisplay\\.php http://www.example.com/forums/%1? [R=301,L]

RewriteCond %{QUERY_STRING} f=[^56][0-9]*$
RewriteRule forumdisplay\\.php http://www.example.com/forums? [R=301,L]

The trailing ? is to erase the original query string

Thank-you for that piece of code. I am going to have to study it since I have 0 experience with this sort of thing. :smiley:

Sorry to double post…

[SIZE=2]I was just wondering if you can quickly check if my 301 redirect code is correct:

[/SIZE]

RewriteCond %{QUERY_STRING} cheese=cheese
 RewriteRule index\\.php http://www.newsite.com/cheese? [R=301,L]

[SIZE=2]

The reasoning is that my dynamic URLs do not properly match my static URLs. For example:

The above code helps me to redirect [/SIZE]
http://www.oldsite.com/index.php?[/SIZE][SIZE=2]cheese[/SIZE][SIZE=2]=[/SIZE][SIZE=2]cheese
to [SIZE=2]http://www.newsite.com/[/SIZE][SIZE=2]cheese[/SIZE][SIZE=2]/[/SIZE] [SIZE=2]

Then, I can modify the above code so that I can redirect

[/SIZE] [SIZE=2]http://www.oldsite.com/index.php?[/SIZE][SIZE=2]cheese[/SIZE][SIZE=2]=articles[/SIZE] to [SIZE=2]http://www.newsite.com/category/[/SIZE][SIZE=2]cheese[/SIZE][SIZE=2]/[/SIZE] [SIZE=2]
which has a completely different URL structure and etc.

As well, I have this code:

[/SIZE]

RewriteCond %{QUERY_STRING} f=10
RewriteRule forumdisplay\\.php http://www.newsite.com/forums/forumdisplay.php/10-Cheese? [R=301,L]


RewriteCond %{QUERY_STRING}  ^f=(.*)$
RewriteRule ^forumdisplay\\.php$ http://www.newsite.com/forums? [R=301,L]

[SIZE=2]

The first part allows me to redirect [/SIZE]http://www.oldsite.com/forumdisplay.php?f=10 to http://www.newsite.com/forums/forumdisplay.php/10-Cheese

While the 2nd part redirects any f=# that is not 10 to http://www.newsite.com/forums

It seems to be working for me but I am not sure if this is the correct approach.
[SIZE=2]
Thank-you for your time!

[/SIZE]