问题
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 redirecth#p://www.site.com/pressreleases/some_release.html
toh#p://www.site.com/pressreleases/details.php?id=1
,
andh#p://www.site.com/pressreleases/another_release.html
toh#p://www.site.com/pressreleases/details.php?id=2
?
Thanks
回答1:
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.
回答2:
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.
来源:https://stackoverflow.com/questions/1915824/301-redirect-of-static-html-to-dynamic-php-page