1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

特定のページが検索結果に表示されないようにする

1
Posted at

この記事は、ラクスパートナーズ AdventCalendar 2025の3日目の記事です。
(個人で25日連続投稿にチャレンジ中のカレンダーになります)


「社内向けページ(開発環境やステージング環境など)がGoogleの検索結果に表示されないようにしたい!」
といった場面はないでしょうか?

そういった時はバックエンドやインフラ側でIP制限することが多いようですが、フロントエンド側でnoindexディレクティブというものを使えば、特定のページを検索結果から完全に削除することができます。

実装方法

エントリーポイントとなるファイル(index.html)のheadタグ内に以下のmetaタグを設置すれば完了です。

index.html
<% if(process.env.NODE_ENV !== 'production') { %>
    <meta name="robots" content="noindex">
<% } %>

<% %>の部分はEJSでJavaScriptのコードを記入できる記法で、その中でif文を使用することにより、本番環境(produciton)以外の環境を指定することができます。
参考:https://qiita.com/miwashutaro0611/items/36910f2d784ff70a527d


あとは<meta name="robots" content="noindex">を設置してあげれば、noindexをサポートする検索エンジンで、社内向けページだけ検索結果に表示されなくなります。

また、Googleのウェブクローラーだけページを検索結果に表示させたくない場合は、以下のように設定するそうです。

<meta name="googlebot" content="noindex">

以上、特定のページが検索結果に表示されないようにする方法でした。


ちなみに、noindexでの対応だと若干タイムラグがあるそうなので、早急に検索結果から削除したい場合はGoogle Search Consoleを活用する方が早そうです。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?