Welcome! Log In Create A New Profile

Advanced

rewrite scheme for url redirect

All files from this thread

File Name File Size   Posted by Date  
img_rewrite.tar.bz2 6.8 KB open | download Antoine BONAVITA 01/27/2011 Read message
nginx.conf 1.3 KB open | download Antoine BONAVITA 01/27/2011 Read message
January 26, 2011 04:11PM
I'm going crazy with this since I can't get it working in any way...

I have a subdomain on a server, let's call it images.site1.com, dedicated to serve images. Due to some bandwidth limitation i got a more capable server so the webpages will remain on site1.com but the images will be moved to images.site2.com

Since I had to change the names of images folders on the new server now I need to rewrite the urls in order to fit my needs. Only the webserver on site1.com runs NginX, so i need to do rewrite the original ruls following a regular expression (regex) and do something like:

http://images.site1.com/oldfolderjpg/123456_1.jpg
--rewrite-->
http://images.site2.com/newfolderjpg/12/34/new_images/123456/123456_image_1_large.jpg

- The first and most logic rewrite scheme I tought about is:

rewrite ^/oldfolder/([0-9][0-9])([0-9][0-9])([0-9][0-9])_([0-9]).jpg$ http://images.site2.com/newfolder/$1/$2/new_images/$1$2$3/$1$2$3_image_$4_large.jpg permanent;But it didn't work (I really don't know why)

- The second way I tried out is:

location /oldfolder/([0-9][0-9])([0-9][0-9])([0-9][0-9])_([0-9]).jpg$ {
rewrite ^ http://images.site2.com/newfolder/$1/$2/new_images/$1$2$3/$1$2$3_image_$4_large.jpg permanent;
}And it didn't work either...

I tried this config too:

location ~ oldfolder/ {
rewrite ^([0-9][0-9])([0-9][0-9])([0-9][0-9])_([0-9]).jpg$ http://images.site2.com/newfolder/$1/$2/new_images/$1$2$3/$1$2$3_image_$4_large.jpg permanent;
}But with no luck...

After that I tried an old config cheme i used for another site (on the same box) for a cdn config:

location ~ /oldfolder/([0-9][0-9])([0-9][0-9])([0-9][0-9])_([0-9]).jpg {
rewrite ^/(.*)$ $scheme://images.site2.com/newfolder/$1/$2/new_images/$1$2$3/$1$2$3_image_$4_large.jpg;
}I've been triying in several ways but nginx keeps ignoring my rewrite scheme redirecting to my default error image located at images.site1.com/error.jpg

Can anyone help me with this?

I'll write down my subdomain server config for your facility:

## images.site1.com ##

server {
listen 80;
server_name images.site1.com;
error_page 404 http://images.site1.com/error.jpg;
root /home/sites/site1.com/images;
}It's a very basic server config, that's why I can't understand why nginx doesn't rewrite the images following such scheme...
Subject Author Posted

rewrite scheme for url redirect

sevy January 26, 2011 04:11PM

Re: rewrite scheme for url redirect

Antoine BONAVITA January 26, 2011 04:42PM

Re: rewrite scheme for url redirect

sevy January 26, 2011 04:47PM

Re: rewrite scheme for url redirect

António P. P. Almeida January 26, 2011 05:18PM

Re: rewrite scheme for url redirect

sevy January 26, 2011 05:58PM

Re: rewrite scheme for url redirect

António P. P. Almeida January 27, 2011 09:40AM

Re: rewrite scheme for url redirect Attachments

Antoine BONAVITA January 27, 2011 04:32AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 274
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready