Optimal way to implement very big redirect list in Apache2

Optimal way to implement very big redirect list in Apache2 - If a page has internal and external outgoing links to redirecting URLs, it’s returning 3xx (301, 302, etc.) HTTP status codes standing for redirection. This issue means that the page does not exist on a permanent or temporary basis. It appears on most of the popular web browsers, usually caused by a misconfigured website. However, there are some steps you can take to ensure the issue isn’t on your side. You can find more details about redirecting URLs by reading the Google Search Central overview. In this article, we’ll go over how you can fix the Optimal way to implement very big redirect list in Apache2 error on your web browser. Problem :


I have about 6000 URLs that need to be redirected after changing the CMS. All those URLs are stored in a DB table together with an ID that allows me to tell what is being referenced. Using this table I could generate one huge .htaccess with a lot of Rewrite rules but I suspect that is very inefficient. What's the best way to go? As far as I can tell there are two options:




  • Using a RewriteMap where the key is the old URL (it contains no ID, just text, so it has to be the whole thing). I wonder if having 100-150 char long keys is gonna work well.

  • Generating a DB table that exactly matches every old/new URL pair and calling some small script to make the redirect.



(Could be summed up as: Is a hash map stored in the filesystem more efficient than a indexed DB table?)



Second part of the question. The new URLs contain the ID of the page being invoked. Something like




www.example.com/abc/21-defghi.html




If instead I call




www.example.com/21-xxx.html




I get a 301 Redirect to the correct URL. Should I bother to generate the exact new URL or is it ok to concatenate two redirects? This means either storing just an ID or the whole new URL.


Solution :

Creating a huge .htaccess can have a serious performance impact on your system as it is read linearly for all requests, at least until a rule with the L attribute (Last Rule) is matched.



The way I did something similar (about 3000 redirects) is to put a custom error page in the .htaccess. From memory the syntax is something like this:



ErrorDocument 404 404.php


Then in 404.php, implement the logic using a MySQL database, searching for the new URL using the requested URL. If it is found, redirect the request using the PHP location header, if not, then display a custom error page.



Unlike simply issuing the 404 redirect in the .htaccess, the 404.php file can keep track of requests and keep stats on the redirects being returned.


We hope that this article has helped you resolve the redirects, mod-rewrite, apache2 error in your web browsers. Enjoy browsing the internet uninterrupted!

Comments

Popular posts from this blog

How to redirect to any domain [duplicate]

"302 found" for index page bad for SEO?

Create redirect from url like www.example.us/?p=100&option=