2
2

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 3 years have passed since last update.

さくらインターネット上でWordPressの内部転送設定をする

Posted at

さくらインターネットのサーバ上でWordPressを運用しているのですが、ドメインルートURLにアクセスした際にサブディレクトリにインストールしたWordPressに内部転送したいと考えました。

例)以下のサイトにアクセス
https://example.com
以下のサイトに内部転送(表示されるURLは変わらない)
https://example.com/wp/

一番簡単なのはhttpd.confファイル内でmod_rewriteを利用した設定を行えばOKです。
※.htaccessでは[L]の設定が有効になりません。

httpd.conf
RewriteEngine On
RewriteRule ^wp/(.*) /$1 [L]

しかし、さくらインターネットで共有サーバを利用しているとhttpd.confは編集できません。
そのため、以下の手順でWordPress側で対応しました。

  1. WordPressの管理画面上で「サイトアドレス」の設定を修正
  2. index.phpと.htaccessファイルをルートにコピー
  3. index.phpと.htaccess内のフォルダ記述を修正する

WordPressの管理画面上で「サイトアドレス」の設定を修正

WordPressの管理画面にログインし、「設定」→「一般」を開きます。
「サイトアドレス」のところに記載されたURLをルートに書き換えます。
※「Word Pressアドレス」の方は修正しません。

スクリーンショット 2022-01-27 11.38.10.png

index.phpと.htaccessファイルをルートにコピー

sshまたはftpなどを利用して/wp/以下のindex.phpと.htaccessファイルを/にコピーします。

index.phpと.htaceess内のフォルダ記述を修正する

コピーした/index.phpの以下の部分を修正します。

index.php
// 修正前
require( dirname( __FILE__ ) . '/wp-blog-header.php' );

// 変更後
require( dirname( __FILE__ ) . '/wp/wp-blog-header.php' );

コピーした/.htaccess内で/wp/の記載がある部分も/に修正します。

.htaccess
・・・
# 変更前
RewriteBase /wp/
# 変更後
RewriteBase /
・・・
# 変更前
RewriteRule . /wp/index.php [L]
# 変更後
RewriteRule . /index.php [L]
・・・

まとめ

WordPressのプラグインなどを使ってキャッシュが効いているとすぐには反映しないので、キャッシュをオフにするなどして確認する必要があります。
必ずバックアップを取ってから行ってくださいね。

参考

2
2
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
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?