I'm moving a sizable static website of 500+ pages to some Joomla installation but things i am thinking of doing, instead of code a 500+ line .htaccess file, is by using PHP's built-in 301 header redirect to dynamically redirect demands which come to the new URL.

So for instance, once i slowly move the site, the next URL would 404 with no redirect-


I'd would like it to redirect to


So I must produce a MySQL database of old Web addresses as well as their corresponding new URL after which, when the server will return a 404, for this first to determine the DB for that existing old URL, and when matched up, to problem a 301 redirect towards the new URL. Right, shall we be held making sense here?

Wouldso would I actually do that? I'm able to "talk" the logic although not really sure where to start or how you can do it because, as i understand PHP, I do not really know how this could use Apache (or even when it might for instance...)?

And when you realize associated with a scripts available which are already carrying this out, all of the better.

Inside your Apache configuration, set an ErrorDocument of whatever /404handler.php script you want. In the run context, $_SERVER['REQUEST_URI'] would be the URI from the original page asked for. Do your database research, and when you get a page you need to redirect do, use header("Location: " . $wherever) to redirect into it.

The easiest way will be able to think about is always to use mod_rewrite (link would be to an excellent introduction tutorial) to redirect ALL incoming demands to some single PHP script (or make use of a flag to ensure that this redirect only happens when the request is perfect for personal files that doesn't exist), using the asked for address passed included in the query string. After that, possess the PHP script lookup where that request is going to, and redirect into it.

Therefore if someone attempts to open http://www.foo.com/old_page.html, the mod_rewrite would send to something similar to http://www.foo.com/redirect.php?page=old_page.html. redirect.php then does a database research to determine exactly what the new address for "old_page.html" is, and redirects to there.

Rather than developing a database, why don't you just put a redirect right into a page using the old URL (ie. old_page.html)?

As you are clearly carrying this out on the situation-by-situation basis using the database records, you can simply do it as being a situation-by-situation basis using the pages.

You can write a fast perl script or whatever you love to generate these html pages for you personally given a classic page's title and also the Link to the brand new page.

You might make use of a [cde]:


But you will have to define that map in your soul httpd.conf (or virutal host configuration):

old_page new-page
# …

After that you can use that map inside your .htaccess file:

RewriteMap oldtonew txt:/path/to/file/map.txt