2018年1月16日火曜日

htaccess等による30xリダイレクトが使えない際のページリダイレクト

htaccess等による30xリダイレクトが使えない際のページリダイレクト


サーバ側で301、302リダイレクトができない状況下で、
特定のURLへのアクセスを、特定ページへリダイレクトさせたい、というお話。

window.location.hrefに、http-equiv="refresh"もおまけして、
以下な感じのリダイレクト用index.htmlを設置しました。

<!DOCTYPE html>
<html>
<head>
<title>Redirect page</title>
<meta charset="utf-8">
<meta http-equiv="refresh" content="0; url=//djeeeno.blogspot.com/">
<script>window.location.href = "//djeeeno.blogspot.com/";</script>
</head>
<body>
Please click <a href="//djeeeno.blogspot.com/">here</a> if you are not redirected automatically.
</body>
</html>

コピペする際には//djeeeno.blogspot.com/を置換してください。


余談ですが、Googlebotさん的には、以下な感じらしいです。

可能なら、htaccessなり、サーバ側で30xリダイレクトの方が良いみたいですね。


参考
Google がサポートしているメタタグ - Search Console ヘルプ


2018/02/05 追記 そのHTMLの書き方、本当に合ってますか? - HTMLの検証を行う「Nu Html Checker」を以て修正したものを追記しました。

<!DOCTYPE html>
<html>
<head>
<title>Redirect page</title>
<meta charset="utf-8">
<meta http-equiv="refresh" content="0; url=//djeeeno.blogspot.com/">
<script>window.location.href = "//djeeeno.blogspot.com/";</script>
</head>
<body>
Please click <a href="//djeeeno.blogspot.com/">here</a> if you are not redirected automatically.
</body>
</html>