Tutorials: Mass re direction

phillipadsmith edited this page Aug 16, 2010 · 1 revision
Clone this wiki locally

Just as a refresher, I had asked:

Related to the above (but slightly off-topic), I’m wondering what folks are doing these days for mass re-direction? In the past, I’ve used a combination of mod_alias and mod_rewrite to ensure that links still work when launching a new site with different story URLs than it previously had. However, I’m wondering what other folks have done when needing to re-direct say 5000 old URLs to new ones?

And David had suggested:

“Most of our customers have written custom mod_rewrite scripts that look up the new → old mapping in a DB file for the redirection. I’ve also suggested creating dummy Bricolage stories for the old URIs, and have templates that just generate a simple page that does a REDIRECT_PERMANENT.”

Mixing all that together, I came up with this recipe:

  1. New Output Channel called htaccess with a file extension of htaccess
  2. New story type called Re-directs (might move that to a per category Cover-type story eventually)
  3. New template called htaccess that:
    1. Looks for stories with an “Old site URL” element in them (which folks have been entering as they go)
    2. Prints out the RedirectPermanent rule
    3. Prints out any “extra” stuff, like RedirectMatch rules that are entered right in the Re-direct story. This writes a /.htaccess file which does the trick.

At the moment, there’s no noticeable speed difference on our front- end server, and we’re using .htaccess files elsewhere (required by other applications) — so I suspect this will continue to work well into the 1000s or 10,000s of rules.

There you go! :-)