I have a website where I need to change the URL structure. The old URLs look like /olddir/part1_de.htm
, the new ones will look like /newdir/sub/category/anotherpage.htm
. There are a lot of URL rewrites I need to do, I assume about 500 distinct rewrites in the end.
As my website gets quite a lot of traffic, my main concern is about performance at the moment. My questions are:
- I assume that for each request, the rewrites block will be parsed and the regex will be evaluated. Am I right?
- Will there be a performance penalty if I use these rewrites? Can nginx handle this?
- Are there any "best practices" to follow when doing a lot of rewrites?
You may find the map module to perform better, especially if most of the URLs don't actually need to be regular expressions. For example (not tested):
Nginx compiles its configuration into some sort of binary tree during initial start or configuration reload (not with each request). So it is OK to use rewrites, but recommended option and best practice is to use try_files directive when possible.