What is better location regex or map regex?

Hi.

I try to transform the pligg htaccess rules to nginx.

There is one from 2010

http://www.edwardawebb.com/web-development/running-pligg-nginx-rewrite-rules

this transformation have some optimization potential, imho ;-).

I would use

location / {
rewrite $uri $dest last;
try_files $uri /index.php;
}

instead of

if (!-e $request_filename){

}

and

map $uri $dest {
‘~^/advanced-search/?$’ ‘/advancedsearch.php’;
‘~^/profile/?’ ‘/profile.php’;

‘~^/([^/]+)/?$’ ‘/index.php?category=$1’;
‘~^/([^/]+)/page/([^/]+)/?$’ ‘/index.php?category=$1&page=$2’;
}

or

location ~ ^/advanced-search/?$ {
rewrite ^/advanced-search/?$ /advancedsearch.php last;
}

location ~ ^/profile/? {
rewrite ^/profile/? /profile.php last;
}

What is your suggestion for the fastest and smallest solution.

thanks aleks

I would use:

  • rewrite directives only at server level, no need for location here
  • a single regex with OR logic to match both the advancedsearch and the
    profile URI since the rewriting grammar is the same
  • a single regex for both ‘index.php’ rewritings, since the grammar of
    category+page is the same as the grammar for page with an optionally
    added
    component

To sum up: 2 rewrite directives at server level.

B. R.