我想讓谷歌和其他機器人永遠洗掉我的舊網頁(410 GONE)并重定向到主頁index.php,其中包括帶有新域鏈接的簡單文本"The site is moved to new domain www.new_domain.com"
因此,請求所有已洗掉的頁面,例如:
www.old_domain.com/about.php
www.old_domain.com/view.php?id=123
應該發送到www.old_domain.com/index.php,回傳代碼 410 給 Google,即“除 index.php 之外的所有頁面都一去不復返了”
實作這一目標的最佳方法是什么?
- 使用
header( "HTTP/1.1 410 Gone" );在 index.php 檔案中插入的PHP 代碼
<!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>
- 或 htaccess 方法:
RewriteEngine On
RewriteBase /
RewriteRule ^robots.txt - [L]
RewriteRule ^(.*)$ https://www.old_domain.com.com/? [G,L]
這似乎不起作用,因為重定向到 Apache 410 錯誤頁面并且訪問者看不到新站點從 index.php 移到何處。
注意:我不想使用301重定向到新域。
uj5u.com熱心網友回復:
“410 Gone”狀態是錯誤狀態,而不是重定向。所有重定向狀態都在 300 秒內。您不能同時提供 410 狀態和重定向。HTTP 規范不允許這樣做。
您可以做的是將自定義頁面設定為“消失”狀態:
ErrorDocument 410 /410-gone.html
并將您的訊息放在該檔案中。然后 Apache 將為所有“消失”的請求提供該訊息,并且不需要重定向。
uj5u.com熱心網友回復:
你可以使用這個:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?olddomain\.com$ [NC]
RewriteRule !index\.php - [R=410,L]
只需olddomain.com在上面的條件模式中替換為您的域名即可。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/380233.html
上一篇:如何通過IP限制對特定重寫的訪問
