在SEO过程中,如何避免网站中出现软404
这篇文章分享一个SEO的问题,软404。我们在网站中经常见到的一个状态码就是404。无论我们是否开发一个网站,这都是要面对的一个问题
何谓软404
在说软404之前,我们首先要了解什么是404。404 是一个 HTTP状态码,表示网页未找到。简单来说,当我们访问一个网页的时候,如果我们请求的网址没有对应的资源,则网站就会返回给我们 “404 网页不存在”
关于HTTP不是我们这篇文章的目的,可以查看HTTP教程了解更多HTTP基础知识。下面我们看一个 404的通用页面

默认情况下,如果我们访问了一个不存在的链接,web服务器会返回给我们上面这样一个页面(Nginx)。但是,如果我们是一个网站运营者,我们会发现直接把这种页面返回给用户,肯定会降低我们网站的逼格。
鉴于此,一般我们都会自己定义一个404页面,我自己网站的404页面是下面这样子的。
访问 https://www.jiyik.com/a.html
软404
关于404我们就介绍这么多,下面我们主要说一下软404。刚开始做网站的时候对软404的概念也不了解。最开始只想着自定义404页面来提升用户的体验。 但是有一个问题没有注意到,如果是纯静态的,可以直接通过Ningx或者Apache等web服务配置自己的404页面。这种是没有什么问题的。但是如果是那种动态的页面,我们是需要在代码中判断用户所请求的资源是否存在,如果不存在的话,我们是直接通过模版引擎渲染了一个404页面。 简单看一下代码
if (count($res) <= 0) {
$this->displayError("404");
return;
}
这里我访问一篇不存在的一篇教程内容,会返回一个404页面
那么问题来了,这里返回给了用户一个404页面,但是我们给的HTTP状态码却是200
。 虽然用户没有什么感觉,但是要做SEO,对于搜索引擎来说,它会认为你这是赤裸裸的欺骗。(其实我是一个SEO小白,我真不是存心要欺骗你的)
上面这种情况也就是我们今天要介绍的主角,软404。所谓软404,就是给用户展现的是一个404的页面,但是实际的HTTP状态码却是200。
所以要解决软404,其实很简单,就是返回给用户一个404页面的同时,把响应的状态码也改成404或者410即可。这个要看你的网站所用的编程语言了。然而不管是什么语言,最核心的还是HTTP协议。
对于PHP来说,其实是比较简单的,可以通过 header
来修改响应状态码
header("status: 404 Not Found");
修改之后,再请求相同地址的时候,在返回了自定义404页面的同时,状态码也变成了404。
总结
开发维护一个网站真心不是容易,如果只是开发出来对于一个程序员来说不是什么难事。但是其中很多的细节是需要我们用心去做的。我个人是一个开发者,对于SEO真心是一个小白,边做边学习边修改吧。 如果不是开发人员,要想做好一个网站,不论是用cms还是其他的框架,都希望能了解一下HTTP协议。现在已经进入了HTTP2.0的时代了。有兴趣也可以了解一下 HTTP2的前世今生 以及 HTTP1.1的不足
推荐阅读:
相关文章
Linux iptables: Incoming and Outgoing Rules Examples (SSH and HTTP)
发布时间:2025/04/20 浏览次数:121 分类:OPERATING SYSTEM
-
In our previous article in the iptables firewall series, we reviewed how to iptables -A add firewall rules using . We also explained how to allow incoming SSH connections. At a high level, it involves the following 3 steps. Delete all exist
HTTP POST request in Node.js
发布时间:2025/04/17 浏览次数:131 分类:Node.js
-
In this article, we will learn how to use Node.js to make a post request using a third-party package. HTTP Post Request in Node.js The HTTP POST method creates or adds resources on the server. The key difference between POST and PUT request
Apache2.4 installation and precautions under Windows7
发布时间:2025/04/08 浏览次数:125 分类:OPERATING SYSTEM
-
To install apache2.4 in Windows 7, we first need to download the apache2.4 installation program. Here we download the software from the apache official website http://httpd.apache.org/download.cgi . First, let's see how to download apache2.
How to use Let's Encrypt with Nginx to configure https in Ubuntu 20.04
发布时间:2025/04/07 浏览次数:123 分类:OPERATING SYSTEM
-
Let's Encrypt is a Certificate Authority (CA) that provides an easy way to obtain and install free TLS/SSL certificates, enabling encrypted HTTPS on your web server. It simplifies the process by providing a software client, Certbot, which a
Linux iptables: Incoming and Outgoing Rules Example (SSH and HTTP)
发布时间:2025/04/07 浏览次数:125 分类:OPERATING SYSTEM
-
In our previous article in the iptables firewall series, we reviewed how to iptables -A add firewall rules using . We also explained how to allow incoming SSH connections. At a high level, it involves the following 3 steps. Delete all exist
How to redirect a website from HTTP to HTTPS
发布时间:2025/03/16 浏览次数:118 分类:NETWORK
-
HTTPS is a protocol for secure communication over computer networks and is widely used on the Internet. More and more website owners are migrating from HTTP to HTTPS, mainly due to the following 5 reasons: Google announced that websites usi
How to Fix the “SSL Handshake Failed” Error (5 Methods)
发布时间:2025/03/16 浏览次数:98 分类:NETWORK
-
Installing a Secure Sockets Layer (SSL) certificate on your WordPress site enables it to use HTTPS for a secure connection. Unfortunately, there are a lot of things that can go wrong in the process of verifying a valid SSL certificate and e
Detailed introduction to Let's Encrypt
发布时间:2025/03/16 浏览次数:131 分类:NETWORK
-
Let's Encrypt is a free, automated, and open certificate authority that officially launched in April 2016. It was originally founded in 2012 by two Mozilla employees. Their goal for founding Let's Encrypt was really simple; to encrypt the e
HTTP2 Tutorial - The Past and Present of HTTP2
发布时间:2025/03/16 浏览次数:73 分类:NETWORK
-
HTTP was originally proposed by Timberners-Lee, a pioneer of the World Wide Web, who designed the application protocol with simplicity in mind to perform advanced data communication functions between web servers and clients. The first docum