[英]PHP cookie set to redirect, googlebot redirects too - how to stop this?
當用戶首次訪問domain.com時,會設置一個cookie,並將其重定向到domain.com/welcome(基本上是索引,但帶有一個僅顯示一次的介紹動畫)。
當用戶第二次訪問該網站時,它停留在domain.com上,不再訪問domain.com/welcome,因為已經設置了cookie。
很簡單。 要對其進行測試,請訪問http://lansana.me
問題是,我在robots.txt中阻止了/ welcome,以防止在搜索結果中出現重復的頁面(因為/和/ welcome頁面的內容基本相同,其中一個頁面的動畫性更高),但是當我嘗試在網站站長中以Google的身份獲取時工具,它表示已重定向到/ welcome頁面(顯然)。 有什么辦法可以告訴Google不要聽我重定向的代碼?
這是我在Laravel中的控制器,用於設置Cookie並重定向或保留在主頁(PHP)上:
public function index()
{
$cookie = 'oreos';
$value = 'redirect';
$expiration = time() + (10 * 365 * 24 * 60 * 60);
$domain = '/';
if (!isset($_COOKIE[$cookie])) {
setcookie($cookie, $value, $expiration, $domain);
$articles = ArticlesModel::latest()->orderBy('created_at', 'desc')->get();
return redirect()->action('ArticlesController@welcome');
}
$articles = ArticlesModel::latest()->orderBy('created_at', 'desc')->get();
return view('pages.index', compact('articles'));
}
public function welcome()
{
$articles = ArticlesModel::latest()->orderBy('created_at', 'desc')->get();
return view('pages.welcome', compact('articles'));
}
這是基本上基於頁面執行不同工作的JavaScript(我不確定該腳本對這個問題有多重要):
// IGNORE THIS LINE
if ($(location).attr('pathname') == '/resume') {
.....
// if current page is /
} else if ($(location).attr('pathname') == '/') {
.....
// If current page is /welcome
} else if ($(location).attr('pathname') == '/welcome') {
.....
}
如果沒有辦法告訴googlebot忽略索引和歡迎方法而只是去索引,是否有更好的方法來實現我正在做的工作而不會與googlebot沖突?
而不是檢查JavaScript中的路徑,而是檢查cookie的存在。 重定向總是很糟糕,因為它會降低性能,甚至對Google也是不利的。
您也可以將cookie創建移動到JavaScript(或什至使用其他存儲),並刪除任何服務器端邏輯。 我認為這一點特別有趣,因為您的功能實際上僅影響演示。 服務器為什么要關心?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.