Forum: NGINX rewrite rule

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
E84e93646376def3fbed0907fe9335e1?d=identicon&s=25 Max (Guest)
on 2009-03-01 15:07
(Received via mailing list)
Hello,

I tried to change the following apache rewrite to work under nginx. But
it's
still not working.

RewriteEngine On
RewriteBase /
RewriteRule ^item-(.*)_(.*)_(.*)_(.*).html$
auction.php?title=$1&item=$2&country=$3&ccid=$4
RewriteRule ^item-(.*)_(.*)_(.*).html$
auction.php?title=$1&item=$2&country=$3
RewriteRule ^item-(.*)_(.*).html$ auction.php?title=$1&item=$2

Could anyone teach me how can I do it correctly? Thanks a lot.

Max
5640e332954fc0006aea97a155ce0afd?d=identicon&s=25 Igor Sysoev (Guest)
on 2009-03-01 17:09
(Received via mailing list)
On Sun, Mar 01, 2009 at 09:58:25PM +0800, Max wrote:

>
> Could anyone teach me how can I do it correctly? Thanks a lot.

      location /item- {
           rewrite  ^/item-(.*)_(.*)_(.*)_(.*).html$
                    /auction.php?title=$1&item=$2&country=$3&ccid=$4
                    last;

           rewrite  ^/item-(.*)_(.*)_(.*).html$
                    /auction.php?title=$1&item=$2&country=$3
                    last;

           rewrite  ^/item-(.*)_(.*).html$
                    /auction.php?title=$1&item=$2
                    last;
      }
F5a6ed477b109fe6acc11a5a8f87e7e8?d=identicon&s=25 mike (Guest)
on 2009-03-01 20:52
(Received via mailing list)
To simplify things you could just point all requests to a single
handler.

rewrite  ^/item-(.*).html$ /handler.php?uri=$1;

then handler.php has something like:

$uri = explode('_', filter_input(INPUT_GET, 'uri',
FILTER_SANITIZE_STRING));
$_GET['ccid'] = isset($uri[4]) ? $uri[4] : '';
$_GET['country'] = isset($uri[3]) ? $uri[3] : '';
$_GET['item'] = isset($uri[2]) ? $uri[2] : '';
$_GET['auction'] = isset($uri[1]) ? $uri[1] : '';
require 'auction.php';

Something of that nature

Or you could just rewrite auction.php (since it is a single script) to
include the stuff above, and instead of forcing $_GET stuff, just
assign it as $request['country'] $request['item'] etc...

(various ways but simplifies webserver configuration, which requires
administrative duties, reloading the server, if it's a multiple
webserver environment each one needs tweaked, etc) - this keeps it in
the userland and really does not add much overhead at all.
E84e93646376def3fbed0907fe9335e1?d=identicon&s=25 Max (Guest)
on 2009-03-02 15:33
(Received via mailing list)
Thanks a lot for the rewrite rule.

I posted the wrong rewrite rule:-( in my origial post. This is the one
that
I want to change:

RewriteEngine On
RewriteBase /
RewriteRule ^images/e/(.*)$ http://thumbs.ebaystatic.com/pict/$1 [R,L]
RewriteRule ^item-(.*)_(.*)_(.*)_(.*).html$
auction.php?title=$1&item=$2&country=$3&ccid=$4
RewriteRule ^item-(.*)_(.*)_(.*).html$
auction.php?title=$1&item=$2&country=$3
RewriteRule ^item-(.*)_(.*).html$ auction.php?title=$1&item=$2

Could someone help me to make it work? Thanks a lot :-).

Max
E84e93646376def3fbed0907fe9335e1?d=identicon&s=25 Max (Guest)
on 2009-03-02 15:35
(Received via mailing list)
Thanks a lot.

Max
561c2fb6d0c72e0c7bc52b263c7d56c3?d=identicon&s=25 Merlin (Guest)
on 2009-03-03 00:55
(Received via mailing list)
Apache:
  RewriteRule ^images/e/(.*)$ http://thumbs.ebaystatic.com/pict/$1 [R,L]
NginX:
  rewrite ^/images/e/(.*)$ http://thumbs.ebaystatic.com/pict/$1
permanent;

If you compare what you sent and what Igor replied with, it should be
pretty
clear that the omitted rule should be very similar.  It wouldn't hurt to
take some time to learn regular expressions, either:
http://www.google.com/search?hl=en&q=learn+regular...
This topic is locked and can not be replied to.