ПРОЕКТЫ 


  АРХИВ 


Apache-Talk @lexa.ru 

Inet-Admins @info.east.ru 

Filmscanners @halftone.co.uk 

Security-alerts @yandex-team.ru 

nginx-ru @sysoev.ru 


  СТАТЬИ 


  ПЕРСОНАЛЬНОЕ 


  ПРОГРАММЫ 



ПИШИТЕ
ПИСЬМА












     АРХИВ :: nginx-ru
Nginx-ru mailing list archive (nginx-ru@sysoev.ru)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Помогите с rewrite



On Thu, Apr 09, 2009 at 05:30:13PM +0400, Igor Sysoev wrote:

> On Thu, Apr 09, 2009 at 05:09:37PM +0400, Alexey V. Karagodov wrote:
> 
> > error_page 404 =404 /404.html;
> > несработает?
> 
> Нет. По-хорошему, нужно расширить try_files для кода:
> 
>    try_files $uri  =404;
> 
>    try_files $uri $uri.html $uri/index.html  =403;

Патч.


-- 
Игорь Сысоев
http://sysoev.ru
Index: src/http/ngx_http_core_module.c
===================================================================
--- src/http/ngx_http_core_module.c     (revision 2009)
+++ src/http/ngx_http_core_module.c     (working copy)
@@ -1144,6 +1144,11 @@
 
         if (tf->lengths == NULL && tf->name.len == 0) {
 
+            if (tf->code) {
+                ngx_http_finalize_request(r, tf->code);
+                return NGX_OK;
+            }
+
             path.len -= root;
             path.data += root;
 
@@ -3939,6 +3944,7 @@
     ngx_http_core_loc_conf_t *clcf = conf;
 
     ngx_str_t                  *value;
+    ngx_int_t                   code;
     ngx_uint_t                  i, n;
     ngx_http_try_file_t        *tf;
     ngx_http_script_compile_t   sc;
@@ -3994,6 +4000,20 @@
         }
     }
 
+    if (tf[i - 1].name.data[0] == '=') {
+
+        code = ngx_atoi(tf[i - 1].name.data + 1, tf[i - 1].name.len - 2);
+
+        if (code == NGX_ERROR) {
+            ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
+                               "invalid code \"%*s\"",
+                               tf[i - 1].name.len - 1, tf[i - 1].name.data);
+            return NGX_CONF_ERROR;
+        }
+
+        tf[i].code = code;
+    }
+
     return NGX_CONF_OK;
 }
 
Index: src/http/ngx_http_core_module.h
===================================================================
--- src/http/ngx_http_core_module.h     (revision 2009)
+++ src/http/ngx_http_core_module.h     (working copy)
@@ -267,7 +267,9 @@
     ngx_array_t               *lengths;
     ngx_array_t               *values;
     ngx_str_t                  name;
-    ngx_uint_t                 test_dir;   /* unsigned  test_dir:1; */
+
+    unsigned                   code:10;
+    unsigned                   test_dir:1;
 } ngx_http_try_file_t;
 
 


 




Copyright © Lexa Software, 1996-2009.