【问题标题】:301 Redirect of Static HTML to Dynamic PHP Page静态 HTML 到动态 PHP 页面的 301 重定向
【发布时间】:2010-12-27 07:31:50
【问题描述】:

升级我们的网站后,人们在博客等中的许多旧链接现在都进入了我们的 404 错误页面。

一个例子是:(使用 h#p b/c 我是新用户,不能发布链接)

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

这些项目现在是 db 驱动站点的一部分,并将在此处使用:

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

如何设置 301 重定向
h#p://www.site.com/pressreleases/some_release.html

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


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

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

谢谢

【问题讨论】:

  • 如果您遵循 Markdown 语法,您可以让我们其他人更清楚您的问题。

标签: http-status-code-301


【解决方案1】:

pressreleases 目录中编写一个.htaccess 文件并指定以下内容:

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

如果您想使用正则表达式进行重定向,请将mod_rewrite 用作explained here

列出了各种选项on this page

【讨论】:

    【解决方案2】:

    如果您有很多这样的 URL,并且假设您可以访问 Apache 配置,请考虑在 /etc/apache2(或其他任何地方)中创建一个“redirects.inc”文件,然后添加“include /etc/apache2 /redirects.inc" 到您的虚拟主机。这样您就可以在一个地方添加/更新您的重定向。

    【讨论】:

    • 谢谢。那么包含页面是否只是一系列“重定向 301...”语句?
    • 没错。如果您有办法将旧链接映射到新链接,您甚至可以自动生成此文件。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-20
    • 1970-01-01
    • 2012-10-11
    相关资源
    最近更新 更多