RewriteMap vs RewriteRule Regex
5 posts
• Page 1 of 1
- lawyercentral
- Posts: 28
- Joined: 16 May 2013, 13:13
RewriteMap vs RewriteRule Regex
First of all, I love Ape. It really does provide fantastic functionality. It's an awesome product.
I have a large number of URLs (about 2,500) that need to be redirected because we are moving to a new CMS.
There are portions of them that could be handled with some rewrite rule regex. For example, I could capture 80 with the following:
There's another group of about 300 that I could use a similar rule for. Some of the others would require slightly more targeted rules, such as:
From a performance/best practices perspective, does it make sense to simply put them all into a RewriteMap? Into multiple rewrite maps? Or should I handle some them with targeted rewrite rules? For example, if 25 rewrite rules like the ones above can handle 800 of the URLs, should I use them and handle the rest with a RewriteMap? Do rules that capture multiple URLS, even with complex regex, improve performance? Or is the map always faster?
Also, is using Ape/.htaccess/RewriteMap faster or better than using IIS 7's rewrite rules and rewrite maps in web.config, like set up below?
Are there performance, caching, or other differences that I should be aware of?
I have a large number of URLs (about 2,500) that need to be redirected because we are moving to a new CMS.
There are portions of them that could be handled with some rewrite rule regex. For example, I could capture 80 with the following:
- Code: Select all
RewriteRule ^/(.*)--6-(.*).html$ http://%{HTTP_HOST}/new-url-here.html [R=301,L,NC]
There's another group of about 300 that I could use a similar rule for. Some of the others would require slightly more targeted rules, such as:
- Code: Select all
RewriteRule ^/(.*)--11-(2109|2093|2106|2111|2089|2102|2104|2096|2099|there could be more or fewer IDs here).html$ http://%{HTTP_HOST}/some-other-new-url-here.html [R=301,L,NC]
RewriteRule ^/(.*)--11-(1870|1875|1871|1877|1878|1873|1881|1879|1880|1864|1859|1854|1857|1856|1851|1852|1853|1855|1858|1863|1862|1860|1861|2348|There could be more or fewer IDs here).html$ http://%{HTTP_HOST}/different-url-here.html [R=301,L,NC]
From a performance/best practices perspective, does it make sense to simply put them all into a RewriteMap? Into multiple rewrite maps? Or should I handle some them with targeted rewrite rules? For example, if 25 rewrite rules like the ones above can handle 800 of the URLs, should I use them and handle the rest with a RewriteMap? Do rules that capture multiple URLS, even with complex regex, improve performance? Or is the map always faster?
Also, is using Ape/.htaccess/RewriteMap faster or better than using IIS 7's rewrite rules and rewrite maps in web.config, like set up below?
- Code: Select all
<system.webServer>
{lots of stuff here}
<rewrite>
<rewriteMaps configSource="RewriteMaps.config" />
<rules configSource="RewriteRules.config" />
</rewrite>
</system.webServer>
Are there performance, caching, or other differences that I should be aware of?
Re: RewriteMap vs RewriteRule Regex
Hello,
Thanks for you kind words about Ape.
As for your situation:
"Do rules that capture multiple URLS, even with complex regex, improve performance? Or is the map always faster?"
- rules that capture multiple URLS are better than a hundred rules each for an individual URL, but map files will be even more efficient. So I would strongly recommend putting all your old_url/new_url pairs into the map file and enjoy increased performance. Plus, your config will be more clear for understanding without the rules with various patterns.
IIS7 rewriter is OK but it does not provide such flexible configuration as Ape. And caching can be adjusted better using Ape modules than standard IIS functionality.
Thanks for you kind words about Ape.
As for your situation:
"Do rules that capture multiple URLS, even with complex regex, improve performance? Or is the map always faster?"
- rules that capture multiple URLS are better than a hundred rules each for an individual URL, but map files will be even more efficient. So I would strongly recommend putting all your old_url/new_url pairs into the map file and enjoy increased performance. Plus, your config will be more clear for understanding without the rules with various patterns.
IIS7 rewriter is OK but it does not provide such flexible configuration as Ape. And caching can be adjusted better using Ape modules than standard IIS functionality.
- lawyercentral
- Posts: 28
- Joined: 16 May 2013, 13:13
Re: RewriteMap vs RewriteRule Regex
Thanks for your help, I really appreciate it. Based on your response I will be using a map rather than a list of rewrite rules.
I just had a few follow-up questions to better understand my options: Is the "dbd" maptype faster or in any other way better than the "txt" maptype? Do the dbd queries get cached or are they run every time? And finally, are there any security issues I should be aware of when using the dbd maptype? I.E SQL injection, plain-text database credentials, etc...
I just had a few follow-up questions to better understand my options: Is the "dbd" maptype faster or in any other way better than the "txt" maptype? Do the dbd queries get cached or are they run every time? And finally, are there any security issues I should be aware of when using the dbd maptype? I.E SQL injection, plain-text database credentials, etc...
Re: RewriteMap vs RewriteRule Regex
Hello,
txt is faster than dbd.
dbd makes request to the database every time you address the mapfile. Connection with database is cached so at least there's no need to connect upon each request.
If you have rules that match (.*) from the URL and paste it into SQL, then you should protect yourself from injections or write rules more carefully.
txt is faster than dbd.
dbd makes request to the database every time you address the mapfile. Connection with database is cached so at least there's no need to connect upon each request.
If you have rules that match (.*) from the URL and paste it into SQL, then you should protect yourself from injections or write rules more carefully.
- lawyercentral
- Posts: 28
- Joined: 16 May 2013, 13:13
Re: RewriteMap vs RewriteRule Regex
Thanks again for your help!
5 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 0 guests