# Apparent bug in rewrite (0.7.65)

**URL:** <https://www.ruby-forum.com/t/apparent-bug-in-rewrite-0-7-65/201202>\
**Category:** NGINX\
**Created:** [January 2, 2011, 9:00pm UTC](https://www.ruby-forum.com/t/apparent-bug-in-rewrite-0-7-65/201202 "2011-01-02T21:00:28Z")\
**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:** [January 2, 2011, 9:00pm UTC](https://www.ruby-forum.com/t/apparent-bug-in-rewrite-0-7-65/201202/1 "2011-01-02T21:00:28Z")

</div>

Hi,

I have an apparent bug in nginx 0.7.65

My config

```auto
server {
  listen 80;
  server_name assets.mysite.com;
  root /usr/share/apache-tomcat-6.0.24/webapps/ROOT/assets;

  rewrite ^/([^/]+)/(.*) /$2;
  expires 90d;
}
```

My request

```auto
2011/01/02 19:51:52 [error] 5824#0: *18 open()
"/usr/share/apache-tomcat-6.0.24/webapps/ROOT/assets/style.css" failed
(2: No such file or directory), client: xxx, server: assets.mysite.com,
request: "GET /28/css/style.css HTTP/1.1", host: "assets.mysite.com"
```

> From this it looks like  
> [http://www.mysite.com/28/css/style.css](http://www.mysite.com/28/css/style.css)  
> gets munged to  
> /style.css  
> when it should be  
> /css/style.css

On apache this works fine and I checked the regex on  
[RegexPlanet: online regular expression testing for Java](http://www.regexplanet.com/simple/) which suggests it’s just fine.

Any suggestions?

Kind regards,

Marc

Posted at Nginx Forum:

> **[Apparent bug in rewrite (0.7.65)](https://forum.nginx.org/read.php?2,162935,162935#msg-162935)**
>
> Hi, I have an apparent bug in nginx 0.7.65 My config \[code\] server { listen 80; server\_name assets.mysite.com; root /usr/share/apache-tomcat-6.0.24/webapps/ROOT/assets; rewrite ^/(\[^/\]+)/(.\*)

---

<div class="post-metadata">

**Author:** ![mschipperheyn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/4491bb/32.png) [@mschipperheyn](https://www.ruby-forum.com/u/mschipperheyn)\
**Post date:** [January 2, 2011, 9:05pm UTC](https://www.ruby-forum.com/t/apparent-bug-in-rewrite-0-7-65/201202/2 "2011-01-02T21:05:29Z")

</div>

I solved it with this regex

```auto
rewrite ^/[^/]+(/.*) /$1
```

Posted at Nginx Forum:

> **[Re: Apparent bug in rewrite (0.7.65)](https://forum.nginx.org/read.php?2,162935,162938#msg-162938)**
>
> Hi, I have an apparent bug in nginx 0.7.65 My config \[code\] server { listen 80; server\_name assets.mysite.com; root /usr/share/apache-tomcat-6.0.24/webapps/ROOT/assets; rewrite ^/(\[^/\]+)/(.\*)

---

<div class="post-metadata">

**Author:** ![mschipperheyn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/4491bb/32.png) [@mschipperheyn](https://www.ruby-forum.com/u/mschipperheyn)\
**Post date:** [January 3, 2011, 5:53am UTC](https://www.ruby-forum.com/t/apparent-bug-in-rewrite-0-7-65/201202/3 "2011-01-03T05:53:20Z")

</div>

Hello!

On Sun, Jan 02, 2011 at 02:58:29PM -0500, mschipperheyn wrote:

> expires 90d;
> 
> Any suggestions?  
> By defining rewrite at server level and not using location / you  
> actually define two rewrites: one at server level, and the same  
> one in implicit location. Or, in other words, server rewrites are  
> also location-level rewrites in implicit location.

Use this instead:

server {  
…

```
location / {
    rewrite ^/([^/]+)/(.*) /$2 break;
}

```

}

Just adding “location / {}” whould do the trick as well, but being  
explicit is a good idea.

Maxim D.
