Don
Don

Reputation: 1570

301 Redirect of Static HTML to Dynamic PHP Page

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

Upvotes: 0

Views: 1559

Answers (2)

Paul Lammertsma
Paul Lammertsma

Reputation: 38272

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.

Upvotes: 5

Mark Porter
Mark Porter

Reputation: 1630

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.

Upvotes: 0

Related Questions