大网数据广告活动
网站运营与故障问答

Removing Some Content from website by giving 410 status code

· 52CE 我爱测

I have some content to be permanently deleted from my website. This is a permanent deletion and I am planning to give 410 status code. I can very well return the status code in PHP page as header( "HTTP/1.1 410 Gone" ); exit or u…

问题原文

原帖链接 · Kiran · CC BY-SA 4.0

I have some content to be permanently deleted from my website. This is a permanent deletion and I am planning to give 410 status code.

I can very well return the status code in PHP page as

header( "HTTP/1.1 410 Gone" );
exit

or using rewrite rule in .htacccess as

RewriteRule ^deleted/ - [L,R=410]

I am clear till this point. However, I would like to redirect users to another page to explain why some pages are no more available.

So, is a redirect to another page with 410 code fine? I am specifically asking this, because I feel it is confusing to redirect to such a page (where search engine may take it as a redirect), but then giving 410 code at the same time.

What is the right approach for this. please help.

已采纳解答

原帖链接 · MrWhite · CC BY-SA 4.0

So, is a redirect to another page with 410 code fine?

A redirect is not necessary. Define a custom 410 error document:

ErrorDocument 410 /error-docs/e410.php

And trigger the 410 in .htaccess, as you did before:

RewriteRule ^deleted/ - [G]

The G flag is simply a shortcut for R=410 and the L flag is not required (it is implied when using a status code other than 3xx).

The error document /error-docs/e410.php is called using an internal subrequest (no external redirect).

In e410.php you can examine the URL that triggered the 410 (ie. $_SERVER['REDIRECT_URL']) if you wish to deliver a specific message for different URLs.

I am specifically asking this, because I feel it is confusing to redirect to such a page (where search engine may take it as a redirect), but then giving 410 code at the same time.

Yes, it is confusing and inefficient. Although search engines will ultimately see the 410 Gone status - so it should still "work" indirectly. But this is inefficient (2 requests/responses) - a 3xx followed by a 410 (in the 2nd - redirected - response). If you "redirect" to your error document then you can't examine details of the initial request that triggered the 410 in the first place.

Reference:

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Webmasters Stack Exchange
适用范围
以原帖系统、软件版本与发布日期为准(2020-01-18)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。