0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【初心者向け】エックスサーバー使用時にURL正規化(301リダイレクト)を行う設定

Last updated at Posted at 2021-07-28

##URLの正規化とは?
URLの正規化とは、同じ内容のページが複数URL存在する場合に、検索エンジンからの評価を向上させるために、評価を集めたいURLを統一することを指します。
##URLを正規化する方法はいくつかある
URLの正規化を行うためには、複数の方法がありますが、今回は301リダイレクトを用いた方法について書きます。
##.htaccessファイルにコードを追加
エックスサーバー内にFTPソフトなどで接続し、.htaccessファイルの5行目あたりにある、IfModule mod_rewrite.cタグ内に以下のコードを記載します。

変更前
<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteBase /
    RewriteRule ^wp-signup\.php 404-siteguard [L]
    RewriteRule ^wp-activate\.php 404-siteguard [L]
    RewriteRule ^login_*****(.*)$ wp-login.php$1 [L]
</IfModule>
変更後
<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteBase /
    RewriteRule ^wp-signup\.php 404-siteguard [L]
    RewriteRule ^wp-activate\.php 404-siteguard [L]
    RewriteRule ^login_*****(.*)$ wp-login.php$1 [L]
-------------------以下の2行を追加----------------------
    RewriteCond %{HTTPS} !on
    RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
</IfModule>
※WordPressで子ページなどに設定が反映されない場合
【www.なしの場合】
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
</IfModule>

【www.ありの場合】
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
</IfModule>

##最後に
私が運営するウェブグロースではWeb制作やSEOに関するお役立ち情報も発信してますので、興味がある方は是非御覧ください。
https://bit.ly/3ow9q94

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?