Webmasters Stack Exchange is a question and answer site for pro webmasters. Join them; it only takes a minute:

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

One of my web applications will be completely replaced by a new system. All URLs will change and thus external links would break. I want to setup Apache httpd to answer with proper 301-redirects to the new URLs.

Now the catch:

There is no formula/regex to derive the new URL from the old, so I need to maintain a mapping list. Ideally I'd like to have it in a location/position where an app I will write allows the content owners to add/edit the mappings themselves. How would I do that?

share|improve this question
up vote 3 down vote accepted

There are several ways to accomplish such redirects:

  • If you have access to the Apache config files (rather than just to an .htaccess file), you could use mod_rewrite with the RewriteMap directive to load your rewrite mappings from a text file or from a database.

  • Otherwise, the easiest way may be to use mod_rewrite in an .htaccess file to redirect all the old URLs to a simple script that will look up the appropriate mapping and return the redirect response. (As an alternative to using mod_rewrite, you could also set the script as your 404 error handler, so that it can process any URLs that are not otherwise handled.)

(And yes, you should use 301 redirects for this, not 302.)

share|improve this answer
Yes 301 it is, I always mix the 2 up when I recall them from memory – stwissel Mar 18 '12 at 7:22

You should use 301 redirects which are permanent, 302 are temporary. The search engines will all handle the 301 the same by indexing the new URL.

You can export a txt file sitemap using XML Sitemaps http://www.xml-sitemaps.com/ put it into excel set your redirects and output the redirects as needed to .htaccess

How many URL's do you have to redirect?

share|improve this answer
There are a few thousand URLs. – stwissel Mar 18 '12 at 7:22

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.