Welcome to WebmasterWorld Guest from 54.197.116.116

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

htaccess redirect old to new

redirect old ids to new with slug

   
1:23 pm on Apr 26, 2014 (gmt 0)

5+ Year Member



I have general knowledge of htaccess. I can rewrite old urls to new...etc. I rebuilt the site and have new URLs with slug etc.. something i did not have before. I have about 4000 urls indexed by search engines.

These current URLs are like so:
exmaple.com/records.php?id=44

My new site URLs are like so:
exmaple.com/record-44-name-of-record

I can redirect each one individually with success with the following code in htaccess:

RewriteCond %{QUERY_STRING} id=44
RewriteRule ^records\.php /record-44-name-of-record? [R=301]

"name-of-record" is from MYSQL DB that i slug in the PHP script.

While the above works perfect. I don't want to manually write 4000 urls in my htaccess. I've tried many different ways based off of what i search here and google without luck.

Thanks for the help. I know that this may have been asked a lot here and I've tried many different ways w/o success.
4:29 pm on Apr 26, 2014 (gmt 0)

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



Internally rewrite those request patterns to a PHP script which does the database lookup and responds with a 301 status code and a Location: header.