# How can i rewrite this?

**URL:** <https://www.ruby-forum.com/t/how-can-i-rewrite-this/220456>\
**Category:** NGINX\
**Created:** [June 10, 2012, 10:57am UTC](https://www.ruby-forum.com/t/how-can-i-rewrite-this/220456 "2012-06-10T10:57:45Z")\
**Posts on this page:** 2\
**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:** [June 10, 2012, 10:57am UTC](https://www.ruby-forum.com/t/how-can-i-rewrite-this/220456/1 "2012-06-10T10:57:45Z")

</div>

i want to rewrite:

[http://a.com/abcde.jpg](http://a.com/abcde.jpg)  
to  
[http://a.com/ab/cde.jpg](http://a.com/ab/cde.jpg)

here is my nginx config:  
rewrite “^/([a-z]{2})([a-z]{3}).jpg$” /$1/$2.jpg last;

but it not works

Posted at Nginx Forum:

> **[how can i rewrite this?](https://forum.nginx.org/read.php?2,227397,227397#msg-227397)**
>
> i want to rewrite: http://a.com/abcde.jpg to http://a.com/ab/cde.jpg here is my nginx config: rewrite "^/(\[a-z\]{2})(\[a-z\]{3})\\.jpg$" /$1/$2.jpg last; but it not works

---

<div class="post-metadata">

**Author:** ![andytse](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/57b2e6/32.png) [@andytse](https://www.ruby-forum.com/u/andytse)\
**Post date:** [June 10, 2012, 12:57pm UTC](https://www.ruby-forum.com/t/how-can-i-rewrite-this/220456/2 "2012-06-10T12:57:32Z")

</div>

Hi,

Avoid rewrite’s:

location ~ ^/([a-z][a-z])([a-z][a-z][a-z]).jpg$ {  
try\_files /$1/$2.jpg $uri;  
}

Andrejs

Posted at Nginx Forum:

> **[Re: how can i rewrite this?](https://forum.nginx.org/read.php?2,227397,227399#msg-227399)**
>
> i want to rewrite: http://a.com/abcde.jpg to http://a.com/ab/cde.jpg here is my nginx config: rewrite "^/(\[a-z\]{2})(\[a-z\]{3})\\.jpg$" /$1/$2.jpg last; but it not works
