We have nearly a hundred thousand paths we need to 301 redirect to a new structure. 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. 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.
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.
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.
What I had in mind:
html.tpl.php
file which has the <header>
part of the page html.tpl.php
, we'd check the MySQL DB to see wether the path requested by the user exists in the new pathalias
table
old path <-> new path
relation was found:
header('Location:');
To 301 redirect the user to the correct new location We've also been told to update the old domain redirects to directly bring the user to the new site without any 301 chaining. 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.
Try the module 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. so you performance will not be affected.
2) The above method should be good enough if not then. 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. E - save the node using node_save()
Cheers, vishal
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.