3

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?

2 Answers 2

3

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.)

1
  • Yes 301 it is, I always mix the 2 up when I recall them from memory
    – stwissel
    Commented Mar 18, 2012 at 7:22
1

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?

1
  • There are a few thousand URLs.
    – stwissel
    Commented Mar 18, 2012 at 7:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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