What is better location regex or map regex?


I try to transform the pligg htaccess rules to nginx.

There is one from 2010


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){



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

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


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

To sum up: 2 rewrite directives at server level.

B. R.