Rewrite

Hello,

I wanted to rewrite this url

rss.xml?type=popular&cid=8
to
/cache/rss/popular_8.xml

so I wrote

            location ~* \.(jpg|jpeg|gif|css|png|js|ico|xml)$ {
                    root /home/site/public_html;
                    access_log      off;
                    expires      30d;

                    rewrite ^rss\.xml?type=popular&cid=(.*)$ 

/cache/rss/popular_8.xml break;
}

But it doesn’t work :confused:
Can anyone help me out with this ? let me know what I’m doing wrong

Posted at Nginx Forum:

Thank you Igor !!!

One more thing, is there a way to put there regular expressions,
something like

location = /rss.xml {
if ($args ~ ^type=popular&cid=([0-9]+) {
rewrite ^ /cache/rss/popular_$1.xml break;
}
}

Posted at Nginx Forum:

Hello!

On Sun, Nov 29, 2009 at 03:53:49PM -0500, thinkbot wrote:

Thank you Igor !!!

One more thing, is there a way to put there regular expressions, something like

location = /rss.xml {
if ($args ~ ^type=popular&cid=([0-9]+) {
rewrite ^ /cache/rss/popular_$1.xml break;
}
}

location = /rss.xml {
    if ($args ~ "^type=popular&cid=([0-9]+)") {
        set $cid $1;
        rewrite ^ /cache/rss/popular_$cid.xml break;
    }
}

Maxim D.

I’ve made it like

location = /rss.xml {
if ($args ~ ^type=popular&cid=([0-9]+)) {
rewrite ^ /cache/rss/popular_$1.xml break;
}
}

and get error: pattern “^” has less captures than referrenced in
substitution “/cache/rss/popular_$1.xml”

I guess its about rewrite ^, so where should I place ([0-9]+) to get the
number ?
I’ve tested with rewrite ^cid=([0-9]+) but doesn’t work

I’m still learning nginx, but it’s great web server

Thank you !

Posted at Nginx Forum:

ohh just noticed post by Maxim D., thank you !!!

Posted at Nginx Forum:

One more thing,
Is there a way to redirect from location rss.xml, to location / depends
on the args ?

           location = /rss.xml {
                   root /home/site/public_html;
                   access_log      off;
                   expires 10m;

                   if ($args ~ "^type=popular&cid=(\d+)") {
                           set $cid $1;
                           rewrite ^ /cache_sql/rss/popular_$cid.xml 

break;
}

                   if ($args ~ "^type=search") {
                           #redirect to location /
                   }
           }

            location / {
                    root /home/site/public_html;
                    access_log      off;
                    proxy_pass http://localhost:8080;
                    proxy_redirect off;
                    proxy_set_header X-Real-IP  $remote_addr;
                    proxy_set_header Host $host;
                    proxy_set_header X-Forwarded-For 

$proxy_add_x_forwarded_for;
}

Posted at Nginx Forum:

On Sun, Nov 29, 2009 at 03:53:49PM -0500, thinkbot wrote:

Thank you Igor !!!

One more thing, is there a way to put there regular expressions, something like

location = /rss.xml {
if ($args ~ ^type=popular&cid=([0-9]+) {
rewrite ^ /cache/rss/popular_$1.xml break;
}
}

Yes. You may also use “\d+” instead of “[0-9]+”.


Igor S.
http://sysoev.ru/en/

On Sun, Nov 29, 2009 at 01:21:14PM -0500, thinkbot wrote:

            location ~* \.(jpg|jpeg|gif|css|png|js|ico|xml)$ {
                    root /home/site/public_html;
                    access_log      off;
                    expires      30d;

                    rewrite ^rss\.xml?type=popular&cid=(.*)$ /cache/rss/popular_8.xml break;
            }

But it doesn’t work :confused:
Can anyone help me out with this ? let me know what I’m doing wrong

 root /home/site/public_html;

 location = /rss.xml {
     if ($args ~ ^type=popular&cid=8) {
         rewrite ^  /cache/rss/popular_8.xml  break;
     }
 }


Igor S.
http://sysoev.ru/en/