如果想让网站的404页面跳转到指定规则的新地址,可以通过下面代码设置:
# define error page
error_page 404 = @notfound;
# error page location redirect 301
location @notfound {
return 301 https://www.maizongai.com;
}
如果想把URL参数也带上,修改为下面内容:
# define error page
error_page 404 = @notfound;
# error page location redirect 301
location @notfound {
return 301 https://www.maizongai.com$request_uri;
}记得将上面的代码放在server内。如果你的是wordpress搭建的网站,可能会阻止了默认的404跳转,需要加入下面代码:
location ~ \.php$ {
fastcgi_pass unix:/tmp/php-cgi.sock; # 保持你原有的 php-fpm 地址不变
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
# 必须加上这一行,WordPress 的 404 才会触发上面的 error_page
fastcgi_intercept_errors on;
}







评论前必须登录!
注册