Welcome! Log In Create A New Profile

Advanced

Re: Problems with some rewrite

August 24, 2010 08:32AM
On Tue, Aug 24, 2010 at 03:15:46AM -0400, revirii wrote:

> Greetings,
>
> i'm currently facing a problem with some rewrites. Given an url i have
> to rewrite it to a local folder.
>
> url: www.domain.com/img/default/420006675369688559/image.png
> doc root: /home/images/public/
> local path (under doc root): 420/006/420006675369688559/default.png
>
> So the rewrite rule should take the number and split it, taking the 1st
> (420) and 2nd (006) three numbers out of the url and rewrite it to the
> local path. But the number isn't always that long, it may also be only 1
> to 5 places long, e.g. 1, 12345 and 456 are possible. If the number is
> less than 6 places long, the rewrite should fill up the missing places
> with the character x.
>
> Optional there's a hyphen in front of the long number, e.g.
> /img/default/[b]-[/b]420006675369688559/image.png
>
> Brilliant concept, but i wasn't asked... So far, so bad. So i wrote some
> rules, but as you might suggest, they don't work. Here they are...
>
> [code]
> # 1 number
> location "/img/default/-?([0-9] {1})/$" {
> rewrite "/img/default/([0-9-] {1})/(.*)\.(.*)$"
> /$1xx/xxx/$1/default.$3;
> }
> # 2 numbers
> location "/img/default/-?([0-9] {2})/$" {
> rewrite "/img/default/([0-9-] {2})/(.*)\.(.*)$"
> /$1x/xxx/$1/default.$3;
> }
> # 3 numbers
> location "/img/default/-?([0-9] {3})/$" {
> rewrite "/img/default/([0-9-] {3})/(.*)\.(.*)$"
> /$1/xxx/$1/default.$3;
> }
> # 4 numbers
> location "/img/default/-?([0-9] {4})/$" {
> rewrite "/img/default/([0-9-] {3})([0-9] {1})/(.*)\.(.*)$"
> /$1/$2xx/$1$2/default.$3;
> }
> # 5 numbers
> location "/img/default/-?([0-9] {5})+/$" {
> rewrite "/img/default/([0-9-] {3})([0-9] {2})/(.*)\.(.*)$"
> /$1/$2x/$1$2/default.$3;
> }
> # 6 or more numbers
> location "/img/default/-?[0-9]+/$" {
> rewrite "/img/default/(-?[0-9]+ {3})(-?[0-9]+
> {3})(-?[0-9]+)/(.*)\.(.*)$" /$1/$2/$3/default.$5 break;
> }
> [/code]
>
> Maybe i don't even need the locations... I've tried the last rule alone,
> with a rewrite to a website, but even that doesn't work, so there must
> be some severe (logical) error in the location/rewrite rule.
>
> Any help would be weclome :-)

You DO need the locations, but you DO NOT need the rewrites.
Why do you use space in "([0-9] {2}" ?
Here is example for 2 numbers location:

# 2 numbers
location ~ ^/img/default/-?(\d{2})/.+\.(.+)$ {
alias /home/images/public/$1x/xxx/$1/default.$2;
}


--
Igor Sysoev
http://sysoev.ru/en/

_______________________________________________
nginx mailing list
nginx@nginx.org
http://nginx.org/mailman/listinfo/nginx
Subject Author Posted

Problems with some rewrite

revirii August 24, 2010 03:15AM

Re: Problems with some rewrite

revirii August 24, 2010 04:45AM

Re: Problems with some rewrite

Igor Sysoev August 24, 2010 08:32AM

Re: Problems with some rewrite

revirii August 24, 2010 08:52AM

Re: Problems with some rewrite

revirii August 24, 2010 10:10AM

Re: Problems with some rewrite

Igor Sysoev August 24, 2010 06:06PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 50
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready