SATOHOST
No Result
View All Result
Thứ Năm, Tháng Tư 15, 2021
  • Login
  • vps giá rẻ
  • cpanel nulled
  • bitcoin exchange script
  • Home 1
Subscribe
SATOHOST
  • vps giá rẻ
  • cpanel nulled
  • bitcoin exchange script
  • Home 1
No Result
View All Result
SATOHOST
No Result
View All Result
Home Blog

How to Force Apache To Show a HTTP-410 Gone Status Code

admin by admin
Tháng Sáu 3, 2019
in Blog
6 min read
0
152
SHARES
1.9k
VIEWS
Share on FacebookShare on Twitter

I removed www.example.com/foo/file.html from my domain. But, it is still being crawled by Google/Yahoo and many other bots. How do I return a HTTP-410 gone error i.e. tell these bots that resource permanently does not exist using Apache HTTPD server on a CentOS/RHEL/Fedora/Ubuntu/Debian and Unix-like operating system?

The http error status code 410 indicates that the resource (images,css,js and all other files) requested is no longer available and will not be available again ever. This 410 status code may be used when a resource has been intentionally deleted or part of unique url generated using some sort of token for given session (for example cached pdf file). Upon receiving a 410 status code, the client or bot should not request the resource again in the future. Bots such as search engines should remove the resource from their index. In this quick tutorial you will learn how to serve HTTP status code 410 from Apache rather than a 404 or 403 error code.

Configuration

The simplest configuration is to add the following line in .htaccess file using mod_alias Redirect directive. Cd to your DocumentRoot such as /var/www/html/:
$ cd /var/www/html/
$ vi .htaccess

Append the following line:
Redirect gone /foo/file.html
OR
Redirect 410 /foo/bar/demo.php
You can also use of regular expressions using RedirectMatch directive as follows:

# Syntax
RedirectMatch gone regex-here
 
# Match all .png files in /foo/
RedirectMatch gone "/foo/.png$"
 
# Another example for gif files starting with bar name
RedirectMatch gone "/foo/bar*.png$"
 
# One more example. We now have resposive site so remove all old mobile friendly html pages
RedirectMatch gone "/mobilesite/*.html$"

# Syntax
RedirectMatch gone regex-here # Match all .png files in /foo/
RedirectMatch gone "/foo/.png$" # Another example for gif files starting with bar name
RedirectMatch gone "/foo/bar*.png$" # One more example. We now have resposive site so remove all old mobile friendly html pages
RedirectMatch gone "/mobilesite/*.html$"

Adding friendly message page

Although the Apache Server disparages generic error responses in the event of 4xx or 5xx HTTP status codes, these responses are rather stark, uninformative, and can be intimidating to site users. You may wish to provide custom error responses which are either friendlier, or in some language other than English, or perhaps which are styled more in line with your site layout. So append the following code:

ErrorDocument 410 /errorpages/410-mobile.gone.html

ErrorDocument 410 /errorpages/410-mobile.gone.html

Save and close the file. Next create 410-mobile.gone.html in your DocumentRoot directory (for e.g. /var/www/html/errorpage/)
$ mkdir /var/www/html/errorpage/ && cd $_
$ vi 410-mobile.gone.html

Append the error message as per your needs:

<html>
<head>
   <title>Page Gone - 410 Error</title>
</head>
<body>
<blockquote>
<h1>Error 410 - Page deleted or gone</h1>
This might be because:
<ul>
  <li>You have typed the web address incorrectly, or the page you were looking for may have deleted.</li>
</ul>
Please try the following options instead:
<ul>
  <li>Use <a href="/search.html">search option</a> to see if it's available elsewhere. Or visit our home page for the latest info.</li>
</ul>
<hr>
<small>If you feel like it, mail the url, and where you came from to webmaster@example.com</small>
</blockquote>
</body>
</html>

<html>
<head>
<title>Page Gone – 410 Error</title>
</head>
<body>
<blockquote>
<h1>Error 410 – Page deleted or gone</h1>
This might be because:
<ul>
<li>You have typed the web address incorrectly, or the page you were looking for may have deleted.</li>
</ul>
Please try the following options instead:
<ul>
<li>Use <a href="/search.html">search option</a> to see if it’s available elsewhere. Or visit our home page for the latest info.</li>
</ul>
<hr>
<small>If you feel like it, mail the url, and where you came from to webmaster@example.com</small>
</blockquote>
</body>
</html>

Your visitor will see the page as follows along with HTTP/1.1 410 gone status code:

Fig.01: HTTP/1.1 410 gone HTML page sample

Verify error code

Simply type the following curl command:
$ curl -I www.example.com/foo/page.html
$ curl -I www.example.com/mobilesite/4242.html

Sample outputs:

HTTP/1.1 410 Gone
Server: Apache
Date: Mon, 14 Dec 2015 14:52:28 GMT
Content-Type: text/html
Content-Length: 335
Connection: keep-alive

Please note that you must get ‘HTTP/1.1 410 Gone’ as status code.

How do I generate a HTTP-410 error for complete domain?

Add the following to your VirtualHost or .htaccess. This is done using mod_rewrite:

   RewriteEngine On
   RewriteCond %{HTTP_HOST} ^www.example.com$ [NC]
   RewriteRule ^(.*)$ - [L,G]

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.example.com$ [NC]
RewriteRule ^(.*)$ – [L,G]

Save and close the file.

References
  • Apache custom error pages.
  • Mod_alias documentation.
  • Mod_rewrite documentation.
Share on Facebook Twitter

Posted by: SXI ADMIN

The author is the creator of nixCraft and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.

Tags: blog
admin

admin

Related Posts

Blog

LINUX BACKUP & RESTORE FULL OS

Tháng Mười Hai 16, 2020
Blog

VPS Ram 4GB Chỉ 199k/tháng Miễn Phí Gsuite,

Tháng Tám 29, 2020
Blog

Tài Khoản Google Drive Unlimited 2020 50k – Google Drive Không Giới Hạn – Google drive unlimited 2020

Tháng Bảy 11, 2020
Bán tài khoản MOVO CASH USA ACCOUNT (VCC+VBA)
Blog

Bán tài khoản MOVO CASH USA ACCOUNT (VCC+VBA)

Tháng Bảy 11, 2020
Blog

Hướng dẫn kích hoạt bản quyền Windows Server 2012 R2 không cần crack

Tháng Sáu 10, 2020
Hướng dẫn cài đặt và cấu hình Openstack toàn tập từ A-Z
Blog

Hướng dẫn cài đặt và cấu hình Openstack toàn tập từ A-Z

Tháng Sáu 4, 2020
Hướng dẫn Tự Tạo Ứng Dụng Họp Online Phòng Học Online Miễn Phí với Jitsi
Blog

Hướng dẫn Tự Tạo Ứng Dụng Họp Online Phòng Học Online Miễn Phí với Jitsi

Tháng Tư 13, 2020
Hướng dẫn sử dụng Remote Desktop để truy cập VPS
Blog

Hướng dẫn sử dụng Remote Desktop để truy cập VPS

Tháng Tư 12, 2020
Download Kali Linux 2020.1
Blog

Download Kali Linux 2020.1

Tháng Tư 12, 2020
vps giá rẻ
  • Trending
  • Comments
  • Latest
Hướng dẫn cài DirectAdmin Nulled mới nhất 2020

Hướng dẫn cài DirectAdmin Nulled mới nhất 2020

Tháng Sáu 10, 2020
Wowza Streaming Engine 4.7.7 Crack Linux/Windows

Wowza Streaming Engine 4.7.7 Crack Linux/Windows

Tháng Mười Một 15, 2020
Hướng dẫn cài đặt và cấu hình Openstack toàn tập từ A-Z

Hướng dẫn cài đặt và cấu hình Openstack toàn tập từ A-Z

Tháng Sáu 4, 2020
Nén và giải nén trong linux centos 6 centos 7 nén zip, tar.gz và tar.bz2.

Khuyến mãi vps 50k/tháng SSD 50Gb

Tháng Sáu 15, 2019
Bán tài khoản MOVO CASH USA ACCOUNT (VCC+VBA)

Bán tài khoản MOVO CASH USA ACCOUNT (VCC+VBA)

Tháng Bảy 11, 2020

Cpanel Nulled Cpanel/whm Nulled on Centos VPS/Dedicated Servers

Tháng Mười 8, 2020

LINUX BACKUP & RESTORE FULL OS

0

Milestones & Timeline

0

The Economics of Websites

0

The Landing Page Guide

0

The Next Big Thing

0

UX Design Is Easy

0

LINUX BACKUP & RESTORE FULL OS

Tháng Mười Hai 16, 2020

VPS Ram 4GB Chỉ 199k/tháng Miễn Phí Gsuite,

Tháng Tám 29, 2020

Tài Khoản Google Drive Unlimited 2020 50k – Google Drive Không Giới Hạn – Google drive unlimited 2020

Tháng Bảy 11, 2020
Bán tài khoản MOVO CASH USA ACCOUNT (VCC+VBA)

Bán tài khoản MOVO CASH USA ACCOUNT (VCC+VBA)

Tháng Bảy 11, 2020

Hướng dẫn kích hoạt bản quyền Windows Server 2012 R2 không cần crack

Tháng Sáu 10, 2020
Hướng dẫn cài đặt và cấu hình Openstack toàn tập từ A-Z

Hướng dẫn cài đặt và cấu hình Openstack toàn tập từ A-Z

Tháng Sáu 4, 2020
  • vps giá rẻ
  • cpanel nulled
  • bitcoin exchange script
  • Home 1
Call us: 0975757375

© 2020

No Result
View All Result
  • vps giá rẻ
  • cpanel nulled
  • bitcoin exchange script
  • Home 1

© 2020

Welcome Back!

Login to your account below

Forgotten Password?

Create New Account!

Fill the forms bellow to register

All fields are required. Log In

Retrieve your password

Please enter your username or email address to reset your password.

Log In