0
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?

ドメイン移転や集約時に使える、.htaccessを用いた301リダイレクト設定

0
Posted at

1. 概要

複数のドメイン(旧ドメインやサフィックス違いなど)を、一つのメインドメインに恒久的に統合するための設定方法です。SEO評価を引き継ぐ「301リダイレクト」を、Webサーバーの構成ファイルである .htaccess を用いて実現します。

2. 前提条件

3. 実装コード(具体例)

sample-domain1.comからsample-domain2.comに転送する場合

転送元ドメイン(sample-domain1.com)の public_html 直下にある .htaccess に以下を記述します。

<IfModule mod_rewrite.c>
  RewriteEngine On
  # 自身のドメイン(sample-domain2.com)以外からのアクセスを、新ドメインの同構造のパスに転送
  RewriteCond %{HTTP_HOST} !^sample-domain2\.com$ [NC]
  RewriteRule ^(.*)$ https://sample-domain2.com/$1 [R=301,L]
</IfModule>

4. 設定のポイント(エックスサーバー等での配置例)

FTPクライアントやファイルマネージャーを使用し、「転送元」のドメイン専用ディレクトリに配置します。

  • 配置パスの構造例:

  • エックスサーバー: /sample-domain1.com/public_html/.htaccess

  • ロリポップ: /(sample-domain1.com用に設定した公開フォルダ)/.htaccess

  • さくらインターネット: /home/ユーザー名/www/sample-domain1.com/.htaccess

  • 重要なポイント:

  • 転送先の .htaccess にはこの記述を書かない(無限ループの原因になる)。

  • 既存の記述がある場合は、ファイルの一番上に追記する。

5. なぜこの方法が良いのか?


0
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
0
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?