Nginx 重定向一些 url (return 404)

Nginx redirect for some url (return 404)

如何为 url returned 创建重定向到 404(在 cms 中)。使用nginx+php-fmp.

例子。有一个类别 /auto/ 有 4 页:

  1. /auto.html,
  2. /auto/page-2.html,
  3. /auto/page-3.html,
  4. /auto/page-4.html

其他人如何 urls (/auto/page-5.html ... /auto/page-200.html) return 301 至 /auto.html?

此代码,return 301 用于所有 url(/auto/page-2.html,/auto/page-5.html ...)。错误是什么?

location ~* /(auto)/page-\d+\.html {
  error_page 404 = @page;
}
location @page {
  rewrite /(.*?)/page-\d+\.html http://site.ru/.html permanent;
}
error_page 404 =404       /404.html;
location ~* \.php$          {
  include                   fastcgi_def;
}
location /                  {try_files $uri /index.php?$args;}

解决方案

error_page 404 =404         /404.html;
  location ~* \.php$          {
    include                   fastcgi_def;
    include                   add/cachephp;
    if ($request_uri ~ /(.+)/page-\d+\.html) {
     error_page 404 = @page;
    }
    fastcgi_intercept_errors on;
  }
  location /                  {try_files $uri /index.php?$args;}

  location @page {
    if ($request_uri ~ /(.+)/page-\d+\.html) {return 301 /.html;}
    return 410;
  }