301 Redirect of Static HTML to Dynamic PHP Page

北城余情 提交于 2019-12-12 04:24:58

问题


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


回答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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!