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

Joergi nginx-forum at
Tue Dec 13 18:29:17 UTC 2016

Hi Francis,

thanks for your answer!

> You don't say what you want to happen to those other files, so I will
> leave it at "nothing special".

Yes, that is right. Files in other folders, also if the names of the files
end on php5, should not be rewritten.

> That is: no-slash, or /wiki/ then no-slash.
>   rewrite ^/([^/]*)\.php5 /$1.php permanent;
>   rewrite ^(/wiki/[^/]*\.php)5 $1 permanent;

I am currently on the way understanding what you are doing here. Pretty
sophisticated and way shorter than what I would have tried. In my tests this
is working as expected. Thanks for the input! :-)

> 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?



Posted at Nginx Forum:,271450,271475#msg-271475

More information about the nginx mailing list