How to rewrite this into nginx?

Igor Sysoev is at rambler-co.ru
Fri Aug 7 17:12:43 MSD 2009


On Fri, Aug 07, 2009 at 03:03:44PM +0200, Robert Gabriel wrote:

> Can someone show me how to rewrite this from Apache to nginx?!
> 
> Thanks you
> 
> .htaccess:
> 
>     Options +FollowSymlinks
>     RewriteEngine On
> 
>     RewriteBase /
> 
>     RewriteCond %{REQUEST_FILENAME} -f [OR]
>     RewriteCond %{REQUEST_FILENAME} -d [OR]
>     RewriteCond %{REQUEST_FILENAME} gallery\_remote2\.php
>     RewriteCond %{REQUEST_URI} !/main\.php$
>     RewriteRule .   -   [L]
> 
>     RewriteCond %{THE_REQUEST} /d/([0-9]+)-([0-9]+)/([^/?]+)(\?.|\ .)
>     RewriteCond %{REQUEST_URI} !/main\.php$
>     RewriteRule .
> /main.php?g2_view=core.DownloadItem&g2_itemId=%1&g2_serialNumber=%2&g2_fileName=%3
> [QSA,L]
>     RewriteCond %{THE_REQUEST} /v/([^?]+)(\?.|\ .)
>     RewriteCond %{REQUEST_URI} !/main\.php$
>     RewriteRule .   /main.php?g2_path=%1   [QSA,L]

It's realy hard to understand reverse logic + sendmail style gobbledygook.
If I understand it right, then:

   location ~ ^/d/([0-9]+)-([0-9]+)/([^/?]+)(\?.|\ .) {
       try_files  $uri  $uri/
           /main.php?g2_view=core.DownloadItem&g2_itemId=$1&g2_serialNumber=$2&g2_fileName=$3;
   }

   location ~ ^/v/([^?]+)(\?.|\ .) {
       try_files  $uri  $uri/   /main.php?g2_path=$1;
   }

   location = /gallery_remote2.php {
       ...
   }

   location = /main.php {
       ...
   }


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





More information about the nginx mailing list