Updating some old "if" statements

Edho Arief edho at myconan.net
Fri Sep 28 11:15:18 UTC 2012


On Fri, Sep 28, 2012 at 2:35 AM, Ian M. Evans <ianevans at digitalhit.com> wrote:
> A few years back this list helped me create some locations that allowed
> some extensionless files to run as php and pass the rest of their path
> along as a variable. I'm wondering if there's been any changes or tweaks
> over the years that would make these locations run less efficiently than
> they could be. As I'm reading this more I'm seeing "If is evil" right?
>
> Location #1:
>
> location ~ /(photos|profile|review|profiles|reviews|news)(/|$) {
> if ($uri ~ ^(.*/(photos|profile|review|profiles|reviews|news))($|/.*)) {
> rewrite ^(.*/(photos|profile|review|profiles|reviews|news))($|/.*)
> $1.php?mypath=$3 last;
> }
> }
>

just remove the if().

> Location #2:
>
> location ~ ^/galleries(/.*$|$) {
> if (-f /usr/local/nginx/htdocs/pixcache$request_uri/index.html) {
> expires 2h;
> rewrite ^(.*)$ /pixcache$1/index.html last;
> break;
> }
> rewrite ^/galleries(/.*$|$) /galleries.php?mypath=$1 last;
> }
>

location ~ ^/galleries(?<mypath>/.*$|$) {
  expires 2h;
  try_files /pixcache$mypath/index.html /galleries.php?mypath=$mypath;
}



More information about the nginx mailing list