# Updating some old "if" statements

**URL:** <https://www.ruby-forum.com/t/updating-some-old-if-statements/223282>\
**Category:** NGINX\
**Created:** [September 27, 2012, 9:36pm UTC](https://www.ruby-forum.com/t/updating-some-old-if-statements/223282 "2012-09-27T21:36:15Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![aris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/258eb7/32.png) [@aris](https://www.ruby-forum.com/u/aris)\
**Post date:** [September 27, 2012, 9:36pm UTC](https://www.ruby-forum.com/t/updating-some-old-if-statements/223282/1 "2012-09-27T21:36:15Z")

</div>

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;  
}  
}

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;  
}

---

<div class="post-metadata">

**Author:** ![Ian\_MSEvans](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/7bcc69/32.png) [@Ian\_MSEvans](https://www.ruby-forum.com/u/Ian_MSEvans)\
**Post date:** [September 28, 2012, 1:16pm UTC](https://www.ruby-forum.com/t/updating-some-old-if-statements/223282/2 "2012-09-28T13:16:19Z")

</div>

On Fri, Sep 28, 2012 at 2:35 AM, Ian M. Evans [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> rewrite ^(._/(photos|profile|review|profiles|reviews|news))($|/._)  
> $1.php?mypath=$3 last;  
> }  
> }

just remove the if().

> 

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

---

<div class="post-metadata">

**Author:** ![Ian\_MSEvans](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/7bcc69/32.png) [@Ian\_MSEvans](https://www.ruby-forum.com/u/Ian_MSEvans)\
**Post date:** [September 29, 2012, 3:39am UTC](https://www.ruby-forum.com/t/updating-some-old-if-statements/223282/3 "2012-09-29T03:39:26Z")

</div>

Thanks for the new locations!

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

I have an older PCRE with my CentOS version, so am I write in  
remembering the named regex can be changed to from ? to  
?P

Thanks again.

---

<div class="post-metadata">

**Author:** ![Ian\_MSEvans](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/7bcc69/32.png) [@Ian\_MSEvans](https://www.ruby-forum.com/u/Ian_MSEvans)\
**Post date:** [September 29, 2012, 10:47pm UTC](https://www.ruby-forum.com/t/updating-some-old-if-statements/223282/4 "2012-09-29T22:47:53Z")

</div>

On Fri, September 28, 2012 7:15 am, Edho A. wrote:

> just remove the if().  
> Strangely, when I removed the “if” on this one and just had the rewrite,  
> I  
> started getting 404 errors.

---

<div class="post-metadata">

**Author:** ![Ian\_MSEvans](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/7bcc69/32.png) [@Ian\_MSEvans](https://www.ruby-forum.com/u/Ian_MSEvans)\
**Post date:** [September 29, 2012, 5:47am UTC](https://www.ruby-forum.com/t/updating-some-old-if-statements/223282/5 "2012-09-29T05:47:57Z")

</div>

On Sat, Sep 29, 2012 at 8:38 AM, Ian E. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> > > rewrite ^/galleries(/.\*$|$) /galleries.php?mypath=$1 last;  
> > > the named regex can be changed to from ? to ?P

I also wrote it wrong, should be /pixcache$request\_uri/index.html
