Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

We will migrate an entire intranet from one CMS to another. All URLs will change in a non-predictable pattern, but I can capture a file with original,new URLs I can feed into anything. I have hundred thousands of URLs, not just a few hundred.

What I would like to do: every URL that is not found (404) should be checked against the database and if a new URL found a 301/308 issued instead. Some trickery to suggest similar pages in the 404 message if the lookup was unsuccessful would be an added bonus.

Is that the right approach or should I check redirection first all the time?

How would I do that in Apache2? Is that a custom 404 module?

share|improve this question
up vote 0 down vote accepted

I figured it out, partly. While the 404 still eludes me, I can use mod_rewrite and the RewriteMap directive to proactively rewrite URLs instead of relying on a 404 status first. This could work:

RewriteEngine on
RewriteMap lowercase int:tolower
RewriteMap blog-map dbm:/home/stw/www/
RewriteRule ^/blog/d6plinks/(.*) /blog/${blog-map:${lowercase:$1}} [NC,R=301,L]

Detailed description here. now with a ErrorDocument statement the original goal might be achievable.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.