本文介绍了Nginx:404 错误时返回 301 重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

每当我的域出现 404 错误时我想做什么,自动 301 到主页.

What I want to do whenever I get a 404 error on my domain, automatically 301 to the homepage.

我有很多旧的博客文章和链接,但我没有在博客上有它们,如果有人碰巧从另一个网站点击,他们会被踢到主页.

I have a lot of old blog posts and such that were linked to, but I don't have them on the blog and if anyone happens to click through from another site that they get kicked to the homepage.

如何在 nginx 中执行此操作?

How can I do this inside nginx?

 server {
        listen             12680;
        root       /home/noahc/webapps/nginx/html/noahc/;
        server_name    www.noahc.net, noahc.net;
        error_page 404 @foobar;

        location @foobar {
                rewrite  .*  / permanent;
                }
         }

推荐答案

这是我使用 webfaction 工作的最终解决方案.

Here is the final solution that I got to work using webfaction.

server {
        listen             12440;
        root       /some/path/here/nginx/html/noahc/;
        server_name    www.domain.net, domain.net;
        port_in_redirect off;

        location /{
            error_page 404 =  @foobar;
        }

        location @foobar {
            rewrite  .*  / permanent;
        }
 }

这篇关于Nginx:404 错误时返回 301 重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-07 02:48