Simon
Simon

Reputation: 121

nginx rewrite from apache 1 rule

Hi need help to reqrite this rule from apache to nginx, trying all day but nothing:

apache: ^pimage/small-([^/.]+)-([^/.]+).jpg$ /img_on_fly.php?iname=$1&iuid=$2&isize=small

tried with all online converters, tried everything I found online and nothing. I have no experience with nginx but other 15 rules rewrited one by one, but all were simple than this, so if someone can. Also, I am not sure what is "location" for this rule in nginx conf?

Upvotes: 0

Views: 160

Answers (2)

DiverseAndRemote.com
DiverseAndRemote.com

Reputation: 19888

try the following in the server element of your conf file

location ~ ^\/pimage\/small\-(?<iname>[^\/\.]+)\-(?<iuid>[^\/\.]+)\.jpg$ {
    try_files $uri /img_on_fly.php?iname=$iname&iuid=$iuid&isize=small
}

your conf file should look like:

server {
    ...
    ...
    ...
}

you can just change it to

server {
    ...
    ...
    ...

    location ~ ^\/pimage\/small\-(?<iname>[^\/\.]+)\-(?<iuid>[^\/\.]+)\.jpg$ {
        try_files $uri /img_on_fly.php?iname=$iname&iuid=$iuid&isize=small
    }
}

Upvotes: 1

What about escaping the dots, like so:

rewrite ^pimage/small-([^/\.]+)-([^/\.]+).jpg$ /img_on_fly.php?iname=$1&iuid=$2&isize=small;

try it and comment back.

UPDATE:
Try escaping the dashes too, like so:

rewrite ^pimage/small\-([^/\.]+)\-([^/\.]+).jpg$ /img_on_fly.php?iname=$1&iuid=$2&isize=small;

After try that, try also the variation of "dots not escaped and dashes escaped".

Upvotes: 0

Related Questions