简体   繁体   English

Drupal:动态质量301重定向

[英]Drupal: Dynamic mass 301 redirecting

We have nearly a hundred thousand paths we need to 301 redirect to a new structure. 我们有近十万条路径需要301重定向到新结构。 Something like: 就像是:

 lang.site.com/section/subsection/article
                  -> 
 lang.site.com/newsection/newsubsection/article

In the past when migrating from domain.com to newdomain.com we would just put a .htaccess file with 10k+ script-generated rows matching old paths to new paths, and it worked okay. 过去,当从domain.com迁移到newdomain.com时,我们只需要放置一个.htaccess文件,其中包含10k +脚本生成的行,将旧路径与新路径匹配,就可以了。 It did not affect the performance of the new domain since the .htaccess was only read by Apache when a user would try to access the old domain. 它不会影响新域的性能,因为.htaccess仅在用户尝试访问旧域时由Apache读取。

This would not work now, since the domain name isn't changing, only the structure of paths. 现在这将无法工作,因为域名没有更改,只能更改路径的结构。 The amount of changing path is nearing the 100 000 mark, so obviously the notion of Apache reading 100 000 lines of .htaccess for each pageload is just absurd. 更改路径的数量接近10万个标记,因此很明显,Apache为每个页面加载读取10万行.htaccess的想法是荒谬的。

I'd love to have some ideas how to implement this properly, with a low performance-cost. 我很想知道一些如何以较低的性能成本正确实现这一点的想法。 I'm not asking you guys for a ready solution, just some help in brainstorming what would be the most feasible solution in our use case. 我并不是要你们提供现成的解决方案,只是在集思广益中提供一些帮助,这将是我们用例中最可行的解决方案。

We are also going to have a Varnish server in front of Apache serving cached content, but I suppose the following solution would still work, since requests that Varnish can't satisfy are forwarded to the Apache in our LAMP environment. 我们还将在Apache的前面放置一台Varnish服务器来提供缓存的内容,但是我想以下解决方案仍然可以使用,因为Varnish无法满足的请求将在我们的LAMP环境中转发到Apache。

What I had in mind: 我的想法是:

  • Drupal 7 has a html.tpl.php file which has the <header> part of the page Drupal 7有一个html.tpl.php文件,该文件具有页面的<header>部分
  • During execution of html.tpl.php , we'd check the MySQL DB to see wether the path requested by the user exists in the new pathalias table 在执行html.tpl.php ,我们将检查MySQL数据库以查看用户请求的路径是否在新的pathalias表中
    • If path not found and old path <-> new path relation was found: 如果找不到路径,并且找到old path <-> new path关系:
      • PHP header('Location:'); PHP header('Location:'); To 301 redirect the user to the correct new location 到301,将用户重定向到正确的新位置
    • Else: 其他:
      • Let Drupal handle the request as usual and continue execution 让Drupal照常处理请求并继续执行

We've also been told to update the old domain redirects to directly bring the user to the new site without any 301 chaining. 我们还被告知要更新旧的域重定向,以不带301链接的方式将用户直接带到新站点。 I suppose we could just utilize the same DB check to see if there is a relation between the oldest path to the newest paths via the old path. 我想我们可以利用相同的数据库检查来查看最旧路径与通过旧路径的最新路径之间是否存在关系。 Luckily we've stored all these even older relations just in case, and now they could be handy. 幸运的是,我们已经存储了所有这些甚至更旧的关系,以防万一,现在它们可以派上用场了。

If you read through, any ideas how to solve this in the best possible manner would be greatly appreciated :) 如果您通读过任何有关如何以最佳方式解决此问题的想法,将不胜感激:)

This is what I would try 这就是我会尝试的

1) The easy method. 1)简单的方法。

Try the module http://drupal.org/project/pathauto 试用模块http://drupal.org/project/pathauto

You can define a pattern for your module. 您可以为模块定义模式。

lang.site.com/newsection/newsubsection/article

lang.site.com/[node:newsection]/[term:newsubsection]

// This is an example not the actual pattern u will use. If you can't seem to get this then 
revert back.

The path will be created only during a cron job. 仅在cron作业期间创建路径。 so you performance will not be affected. 因此您的表现不会受到影响。

2) The above method should be good enough if not then. 2)否则上述方法应该足够好。 You can write a module and implement the below logic 您可以编写一个模块并实现以下逻辑

A - hook_cron() // At every cron run the below should run B - Load the node using node_load() C- Check the uri of the node to your pattern D- If it does not match change it. A-hook_cron()//在每次执行cron时,都应运行以下命令B-使用node_load()加载节点C-检查节点的uri是否与您的模式D-如果不匹配,请进行更改。 E - save the node using node_save() E-使用node_save()保存节点

Cheers, vishal 欢呼雀跃

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

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