I want to let google and other bots that my old web pages are removed forever (410 GONE) and redirect to main page index.php
which includes the simple text with link tonew domain "The site is moved to new domain www.new_domain.com"
So, request to all removed pages like:
www.old_domain.com/about.php
www.old_domain.com/view.php?id=123
should be sent to www.old_domain.com/index.php
, with the return code 410 to Google i.e. "all pages except index.php are gone forever"
What is the best way to achieve this?
- using PHP code
header( "HTTP/1.1 410 Gone" );
inserted in index.php file
<!DOCTYPE html>
<?PHP
header( "HTTP/1.1 410 Gone" );
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="googlebot" content="noindex, nofollow" />
<meta name="robots" content="noindex, nofollow" />
<title>www.old_domain.com</title>
</head>
<body>
The site is moved to <a href="https://www.new_domain.com/"
title="https://www.new_domain.com/">https://www.new_domain.com/</a>
</body>
</html>
- Or htaccess method:
RewriteEngine On
RewriteBase /
RewriteRule ^robots.txt - [L]
RewriteRule ^(.*)$ https://www.old_domain.com.com/? [G,L]
Which seems doesn't work,since redirects to Apache 410 error page and visitors do not see where the new site is moved from index.php.
Note: I do not want to use 301
redirects to the new domain.
CodePudding user response:
A "410 Gone" status is an error status, not a redirect. All redirect statuses are in the 300s. You cannot serve a 410 status AND redirect at the same time. The HTTP spec does not allow that.
What you can do instead is set your custom page for the "gone" status:
ErrorDocument 410 /410-gone.html
And place your message in that file. Then Apache will serve that message for all the "gone" requests and no redirects are needed.
CodePudding user response:
You can use this:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?olddomain\.com$ [NC]
RewriteRule !index\.php - [R=410,L]
Just replace olddomain.com
with your domain name in the condition pattern above.