大网数据广告活动
网站运营与故障问答

Implement lots of redirects (a million) without slowing down the site

· 52CE 我爱测

What's the best way to redirect 1,000,000 unique URLs to another 1,000,000 unique URLs? These pages are all combinations of multiple search filters and queries. We're migrating the site to cleaner URLs and want to map old pages t…

问题原文

原帖链接 · Ricky Sahu · CC BY-SA 4.0

What's the best way to redirect 1,000,000 unique URLs to another 1,000,000 unique URLs?

These pages are all combinations of multiple search filters and queries. We're migrating the site to cleaner URLs and want to map old pages to new ones so that we do not lose visitors or send them to 404s.

I believe a million line .htaccess will slow down the site pretty significantly. Is there a better way that would maintain PageRank but not slow down the site? Maybe something I could put on each page individually?

社区高分解答

原帖链接 · Nick · CC BY-SA 3.0

  1. Store your old and new redirect paths in a database.

  2. Redirect 404 errors to a special 404 page. With Apache and PHP, you could do this with the ErrorDocument directive in your .htaccess:

    ErrorDocument 404 /404.php

  3. In the 404.php script, get the referring page with $_SERVER['REQUEST_URI'], look up the old URL path in your database, and serve a 301 redirect header to the new location if there is one, otherwise show your regular 404 page.

    To issue a 301 header with PHP, you'd useheader("Location: $new_url", true, 301);

The advantage of this over Apache mod_rewrite redirects is that you don't need to process the ruleset for every request – only those that trigger a 404.

The disadvantage is that you have to create a system to manage the rewrite rules in a database, but that's probably worth doing if you have a million rules in the first place.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Webmasters Stack Exchange
适用范围
以原帖系统、软件版本与发布日期为准(2013-07-16)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0 / CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。