Welcome to WebmasterWorld Guest from

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)

New User

5+ Year Member

joined:Dec 26, 2008
posts: 5
votes: 0

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:

My new site URLs are like so:

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

joined:Aug 10, 2004
votes: 118

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.