can some1 please convert this htaccess to nginx rewrite?

Igor Sysoev is at rambler-co.ru
Fri Jan 16 22:09:25 MSK 2009


On Fri, Jan 16, 2009 at 09:41:35AM -0800, mike wrote:

> for vbseo this is all i have for one of my clients:
> 
>         location /forum/ {
>                 rewrite
> ^/forum/((urllist|sitemap_).*\.(xml|txt)(\.gz)?)$
> /forum/vbseo_sitemap/vbseo_getsitemap.php?sitemap=$1 last;
>                 if ($request_filename ~ "\.php$") {
>                         rewrite ^(.*)$ /forum/vbseo.php?vbseourl=$1 last;
>                 }
>                 if (!-e $request_filename) {
>                         rewrite ^/forum/(.*)$ /forum/vbseo.php?vbseourl=$1 last;
>                 }
>         }
> 
> site also has other things (blogs etc) that have their own location
> blocks and it seems to all work great.

The right way:

     location /forum/ {
         error_page  404  = /forum/vbseo.php;
     }

     location ^~ /forum/urllist {
         rewrite ^/forum/(urllist.*\.(xml|txt)(\.gz)?)$
              /forum/vbseo_sitemap/vbseo_getsitemap.php?sitemap=$1 last;
     }

     location ^~ /forum/sitemap_ {
         rewrite ^/forum/(sitemap_.*\.(xml|txt)(\.gz)?)$
              /forum/vbseo_sitemap/vbseo_getsitemap.php?sitemap=$1 last;
     }

     location ~ ^/forum/.+\.php$ {
         fastcgi_pass   ...;
         fastcgi_param  SCRIPT_FILENAME  /path/to/forum/vbseo.php;
         fastcgi_param  QUERY_STRING     vbseourl=$request_uri;
         include        fastcgi_params;
     }

     location = /forum/vbseo_sitemap/vbseo_getsitemap.php {
         fastcgi_pass   ...;
         fastcgi_param  SCRIPT_FILENAME
                          /path/to/forum/vbseo_sitemap/vbseo_getsitemap.php;
         fastcgi_param  QUERY_STRING     $args;
         include        fastcgi_params;
     }


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





More information about the nginx mailing list