Forum Moderators: phranque

Message Too Old, No Replies

Am I doing this right?

Mod Rewrite question on 301.

         

maximillianos

4:32 pm on Dec 12, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hey everyone.

I'm in the process of cleaning up some URLs on one of my sites. Wanted to run my code by the experts, see if I'm doing this right.

Goal: Migrate my long (and ugly) URLs to a cleaner URL without losing any search rank.


# 301 to the new sleaker URL:
RewriteCond %{REQUEST_FILENAME} find_celeb_information
RewriteCond %{QUERY_STRING} celeb=([^&;]*)
RewriteRule ^find_celeb_information.php /people/%1? [R=301,L]

# Re-write it back to orignal script (non-301)
RewriteRule ^people/(.*) new_celeb_info.php?star=$1 [L]

To avoid problems, I copied "find_celeb_information.php" to "new_celeb_info.php". So first I redirect all old requests to "find_celeb_information.php" to the new version in the "people" directory.

Next I then redirect that request to the copied original script (now called "new_celeb_info.php").

It seems to work fine. My old URLs (using "find_celeb_information.php") redirect to the new URL format.

Am I doing this properly if I want to tell the search engines that the old pages (using "find_celeb_information.php") have now moved to the new format in the "people" directory? I want to try and have minimal affect on my rankings.

Thanks for any advice!

g1smd

11:37 pm on Dec 12, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



The redirect should include the domain name as part of the target URL.

That is, requests for either www or non-www URLs with parameters should all redirect to the www version of the correct URL.

jdMorgan

11:53 pm on Dec 12, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Your first two RewriteConds appear to be doing things the hard way. You could replace all three lines with

# Redirect old dynamic URLs to new search-friendly URLs
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /find_celeb_information\.php\?([^&]+&)*celeb=([^&\ ]*)\ HTTP/
RewriteRule ^find_celeb_information\.php http://www.example.com/people/%2? [R=301,L]

This prevents 'infinite' redirect/rewrite looping as your original code does, but using two lines instead of three.

I removed the semicolon from the negative-match subpattern on your query string. If you use semicolons as name/value pair delimiters instead of ampersands, then put change all ampersands to semicolons instead.

Jim

maximillianos

4:52 am on Dec 13, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks for the advice! I added both of your suggestions, everything seems to work great.

I really appreciate the help!