问题原文
原帖链接 · 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
Store your old and new redirect paths in a database.
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.phpIn the
404.phpscript, 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 use
header("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.
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
