views:

233

answers:

2

After upgrading our website, many old links that people have in blogs, etc. are now going to our 404 error page.

An example is: (using h#p b/c I'm a new user and can't post links)

h#p://www.site.com/pressreleases/some_release.html h#p://www.site.com/pressreleases/another_release.html

These items are now part of a db-driven site and would be live here:

h#p://www.site.com/pressreleases/details.php?id=1 h#p://www.site.com/pressreleases/details.php?id=2

How can I set up the 301 to redirect

h#p://www.site.com/pressreleases/some_release.html to h#p://www.site.com/pressreleases/details.php?id=1

and

h#p://www.site.com/pressreleases/another_release.html to h#p://www.site.com/pressreleases/details.php?id=2

??

Thanks

+3  A: 

Compose a .htaccess file in the pressreleases directory and specify the following:

Redirect 301 some_release.html details.php?id=1

If you would like to redirect using regular expressions, use mod_rewrite as explained here.

There are various options listed on this page.

Paul Lammertsma
A: 

If you have a lot of these URLs, and assuming you have access to the Apache config, consider creating a "redirects.inc" file in /etc/apache2 (or anywhere really) and then adding "include /etc/apache2/redirects.inc" to your virtual host. That way you have one place to add/update your redirects.

Mark Porter
Thanks. Would the include page just be a series of "Redirect 301..." statements then?
Don
Exactly. You might even be able to autogenerate this file if you have a way mapping old links to new ones.
Mark Porter