サブディレクトリの WordPress をサブドメインに引っ越したときにトップページ以外の表示で 500 Internal Server Error になる現象に遭遇したので対処しました。
経緯・状況
シチュエーションとしては以下のような状況
- 引っ越し元 WordPress のURL:
https://hoge.example.jp/piyo/fuga/
- 引っ越し先 WordPress のURL:
https://hogera.example.jp/
これで普通に以下の手順を実施しました。
- ファイルダウンロード
- DB エクスポート
wp-config.php
を引っ越し先のDBの情報に書き換え- ファイルアップロード
- DB インポート
- WP-CLI で
https://hoge.example.jp/piyo/fuga
からhttps://hogera.example.jp
に置換wp search-replace --recurse-objects 'https://hoge.example.jp/piyo/fuga' 'https://hogera.example.jp' --allow-root
現象
これでアクセスすると、トップページは正常に表示されるのですがそれ以外のページが 500 Internal Server Error に……。
ログを見てみると以下のようなエラーが。
[Wek Mon dd hh:ii:ss yyyy] [core:error] [pid XXXXX] [client YYY.YYY.YYY.YYY:ZZZZZ] AH00124: Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace., referer: https://hogera.example.jp/
[Wek Mon dd hh:ii:ss yyyy] [core:error] [pid XXXXX] [client YYY.YYY.YYY.YYY:ZZZZZ] AH00124: Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace., referer: https://hogera.example.jp/archives/ID
AH00124: Request exceeded the limit of 10 internal redirects due to probable configuration error. Use ‘LimitInternalRecursion’ to increase the limit if necessary. Use ‘LogLevel debug’ to get a backtrace., referer:
対処
原因としては .htaccess
が引っ越し前の環境を引きずっていたので、それを修正してアップロードすることで解決しました。
before
# BEGIN WordPress
# `BEGIN WordPress` から `END WordPress` までのディレクティブ (行) は
# 動的に生成され、WordPress フィルターによってのみ修正が可能です。
# これらのマーカー間にあるディレクティブへのいかなる変更も上書きされてしまいます。
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /piyo/fuga/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /piyo/fuga/index.php [L]
</IfModule>
# END WordPress
after
# BEGIN WordPress
# `BEGIN WordPress` から `END WordPress` までのディレクティブ (行) は
# 動的に生成され、WordPress フィルターによってのみ修正が可能です。
# これらのマーカー間にあるディレクティブへのいかなる変更も上書きされてしまいます。
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
これで .htaccess
のみアップロードしなおしたところ、正常に表示されるようになりました。
検証はしていませんが、 WP-CLI で仮に .htaccess
も置換できるとしても、上述のようにサブドメインへの置換として絶対URLで置換条件を記述すると、 /piyo/fuga/
のようにサブディレクトリの部分しか記述されていない .htaccess
は置換対象から外れてしまいますね……。
これは盲点でした。