: Optimal way to implement very big redirect list in Apache2 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
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
example.com/abc/21-defghi.html
If instead I call
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.
More posts by @Ravi8258870
1 Comments
Sorted by latest first Latest Oldest Best
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.
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.