简体   繁体   English

将大量旧URL重定向到新URL的最佳方法?

[英]Best approach for redirecting a large number of old URLs to new URLs?

We are re-platforming for a client, and they are concerned about SEO. 我们正在为客户重新平台,他们担心SEO。 Their current site supports SEO friendly URLs, and so does the new platform. 他们的当前站点支持SEO友好URL,新平台也是如此。 So for those, we are just going to create the same URL mapping. 因此,对于这些用户,我们将创建相同的URL映射。 However, they have a large number of other URLs that are not SEO friendly that they want to permanently redirect. 但是,他们还有大量其他的SEO不友好的URL,希望永久重定向。 These do not follow a similar pattern, so one regex in an .htaccess won't cut it. 这些不遵循类似的模式,因此.htaccess中的一个正则表达式将不会削减它。 What is the best way to handle this on a LAMP stack? 在LAMP堆栈上处理此问题的最佳方法是什么? The application has a front controller too, so I need to make sure that works along with the hard redirects. 该应用程序也具有前端控制器,因此我需要确保其与硬重定向一起使用。

One approach (the one I chose ) was to create a simple table of old urls and new ones, and then use mod_rewrite to read the table and perform redirects. 一种方法( 我选择的一种方法)是创建一个包含旧url和新url的简单表,然后使用mod_rewrite读取表并执行重定向。 The table can live in a file external to the Apache config. 该表可以存在于Apache配置外部的文件中。

Alternatively, you could write a script to query a database if you wanted the table to live in a database. 另外,如果您希望表存在于数据库中,则可以编写脚本来查询数据库。

This means you either need to manually create the mapping, or write some script to output this mapping file. 这意味着您需要手动创建映射,或者编写一些脚本来输出此映射文件。

You could use PHP to redirect old URLs to new ones. 您可以使用PHP将旧的URL重定向到新的URL。

header("Location: /new.html",TRUE,301);

You will still need to redirect requests to this PHP script, but you may find this more flexible and easier to debug than exclusively using mod_rewrite. 您仍然需要将请求重定向到此PHP脚本,但是与仅使用mod_rewrite相比,这可能更灵活,更易于调试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM