map v/s rewrite performance

rahul286 nginx-forum at
Tue Mar 25 08:12:52 UTC 2014

Hi All,

I am just wondering, say for 1000 url redirects, what will be more

Rewrite Style:
server {
       rewrite          old-url-1         new-url-1 permanent;
       rewrite          old-url-2         new-url-2 permanent;
       rewrite          old-url-3         new-url-3 permanent;
       rewrite $old-url-1000    $new-url-1000 permanent;

Map Style:

map $request_uri $new_uri {
         default             $request_uri;
         old-url-1          new-url-1;
         old-url-2          new-url-2;
         old-url-3          new-url-3;
         old-url-1000    new-url-1000;

#and something like
server {
         try_files $new_uri =404;

Since nginx is very fast, I am not able to notice any delay for around 20
rewrites. :|

Is one of above 2 method is recommended for large number of rewrites?

I am inclined towards map, as rewrite adds plenty of notices logs. It's like
every rewrite is checked for incoming requests unless it is surrounded by

Please let me know if more details are needed.


Posted at Nginx Forum:,248659,248659#msg-248659

More information about the nginx mailing list