# Rewrite or internal redirection cycle

**URL:** <https://www.ruby-forum.com/t/rewrite-or-internal-redirection-cycle/206038>\
**Category:** NGINX\
**Created:** [April 21, 2011, 1:22am UTC](https://www.ruby-forum.com/t/rewrite-or-internal-redirection-cycle/206038 "2011-04-21T01:22:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [April 21, 2011, 1:22am UTC](https://www.ruby-forum.com/t/rewrite-or-internal-redirection-cycle/206038/1 "2011-04-21T01:22:17Z")

</div>

Hi, I have the following rewrite rule:

```
location = / {
    if ($vanity) {
        rewrite ^/$ /?static_event_cache=1? last;
    }
}

```

Whenever I hit / & vanity is set I get the following error message:

Apr 20 16:16:58 stage-djcore-www1 nginx: 2011/04/20 16:16:58 [error]  
30825#0: \*103 rewrite or internal redirection cycle while processing  
“/”, client: 10.203.66.146, server: , request: “GET / HTTP/1.1”, host:  
“[awesometown.eventbrite.com](http://awesometown.eventbrite.com)”

I get why I have the loop - but I thought (from reading another post  
online) that last would help. Is there anyway to do something like  
this?

Thanks!

–  
Michael Barrett  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![Michael\_Barrett](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/3ec8ea/32.png) [@Michael\_Barrett](https://www.ruby-forum.com/u/Michael_Barrett)\
**Post date:** [April 21, 2011, 3:02am UTC](https://www.ruby-forum.com/t/rewrite-or-internal-redirection-cycle/206038/2 "2011-04-21T03:02:46Z")

</div>

Hello!

On Wed, Apr 20, 2011 at 04:21:17PM -0700, Michael Barrett wrote:

> Apr 20 16:16:58 stage-djcore-www1 nginx: 2011/04/20 16:16:58 [error] 30825#0:  
> \*103 rewrite or internal redirection cycle while processing “/”, client:  
> 10.203.66.146, server: , request: “GET / HTTP/1.1”, host:  
> “[awesometown.eventbrite.com](http://awesometown.eventbrite.com)”
> 
> I get why I have the loop - but I thought (from reading another  
> post online) that last would help. Is there anyway to do  
> something like this?

The “last” means “stop processing rewrites and search for location  
match again”. As the same location will match - cycle is  
expected.

You probably want “break” instead, i.e. “stop processing rewrites  
and handle request here”.

See [GitHub - nginxinc/nginx-wiki: ARCHIVED -- Source for the now archived NGINX Wiki section of https://www.nginx.com · GitHub](http://wiki.nginx.org/HttpRewriteModule#rewrite) for more  
details.

Maxim D.

---

<div class="post-metadata">

**Author:** ![Michael\_Barrett](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/3ec8ea/32.png) [@Michael\_Barrett](https://www.ruby-forum.com/u/Michael_Barrett)\
**Post date:** [April 21, 2011, 5:25am UTC](https://www.ruby-forum.com/t/rewrite-or-internal-redirection-cycle/206038/3 "2011-04-21T05:25:07Z")

</div>

Thanks Maxim!

It turns out that break on the rewrite line made it work.

I then added some caching to the location - and with the break on the  
rewrite line it didn’t ever use the cache. When I used the break  
statement on it’s own however, it seems to work just fine. Do you know  
if that’s expected?

Thanks again!

On Apr 20, 2011, at 6:02 PM, Maxim D. wrote:

> > }  
> > The “last” means "stop processing rewrites and search for location
> 
> * * *
> 
> nginx mailing list  
> [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> [mailman.nginx.org archive](http://nginx.org/mailman/listinfo/nginx)

–  
Michael Barrett  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
