Redirect 针对某个url的Nginx重定向(返回404)
如何为返回到404的url创建重定向(在cms中)。使用nginx+php-fmp 例如。有一个类别/自动/共4页:Redirect 针对某个url的Nginx重定向(返回404),redirect,nginx,rewrite,Redirect,Nginx,Rewrite,如何为返回到404的url创建重定向(在cms中)。使用nginx+php-fmp 例如。有一个类别/自动/共4页: /auto.html /auto/page-2.html /auto/page-3.html /auto/page-4.html 其他URL(/auto/page-5.html…/auto/page-200.html)如何将301返回到/auto.html 这段代码返回301表示所有url(/auto/page-2.html,/auto/page-5.html…)。错误是什么 l
location ~* /(auto)/page-\d+\.html {
error_page 404 = @page;
}
location @page {
rewrite /(.*?)/page-\d+\.html http://site.ru/$1.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 /$1.html;}
return 410;
}
错误_第404页=404/404.html;location~*\.php${include fastcgi\u def;include add/cachephp;if($request\u uri~/(.+)/page-\d+\.html){error\u page 404=@page;}fastcgi\u intercept\u errors on;}location/{try\u files$uri/index.php?$args;}location@page{if($request\u uri~/(.+)/page-\d+\.html){return 301/$1.html;}return 410;}