How do I rewrite files, but only, if they are in one special folder?

Francis Daly francis at
Thu Dec 29 10:47:01 UTC 2016

On Tue, Dec 13, 2016 at 01:29:17PM -0500, Joergi wrote:

Hi there,

> >   rewrite ^/([^/]*)\.php5 /$1.php permanent;
> >   rewrite ^(/wiki/[^/]*\.php)5 $1 permanent;

> > You may want to restrict these to the locations that match their
> > prefixes, depending on what else is happening.
> What do you mean? The "main folder", which you are influencing with your
> first rule, is the web root: /home/$username/www/. The foder wiki is the
> subfolder in there. Any recommendation what location I should add around the
> two rewrites or if I should add one?

Depending on what else is in your config, it may be useful to put the
second rewrite within a "location ^~ /wiki/ {}" block.

But if you don't measure a difference when putting it there, in a
"location ~ \.php5 {}" block, or at server{] level, then it does not
matter in your deployment.


Francis Daly        francis at

More information about the nginx mailing list