前提・実現したいこと
『製品紹介サイト』と『製品販売サイト』をwordpressで作成中です。
同ドメイン内の2つのサブディレクトリ(wp、shop)それぞれにwordpressを入れ、
製品紹介サイトはルートディレクトリで表示されるように設定し、
下記のようなURLの2つのサイトができました。
https://sample.com
https://sample.com/shop/
この2つのサイトに.htaccessによるリダイレクトをかけるため、
『ルートディレクトリ』『/wp/ディレクトリ』『/shop/ディレクトリ』
の3箇所に.htaccessを置き、3箇所とも下記のルールでリダイレクトされるよう記述してみました。
・httpsに統一
・wwwなしに統一
・index.htmlとindex.phpにアクセスされたら、それぞれを省略したURLを表示する
しかし、テストしてみたところ、一部成功・一部失敗している状態です。
発生している問題・エラーメッセージ
『ルートディレクトリ』『/wp/ディレクトリ』は希望通りのリダイレクトが成功しているのですが、
『/shop/ディレクトリ』のみ一部条件でリダイレクトに失敗してしまいます。
失敗の条件をまとめると下記のようでした。
- /shop/index.htmlにアクセスすると、https化・wwwなし化・index省略すべてが失敗する
(/shop/index.phpへのアクセスは、https化・wwwなし化・index省略すべてが成功する)
- wwwありの/shop/にアクセスすると、製品紹介サイトhttps://sample.comに飛んでしまう
(wwwありの/shop/wp-admin/などへのアクセスは、https化・wwwなし化どちらも成功)
(ただし、/shop/wp-admin/index.phpにアクセスすると、/wp/wp-admin/に飛んでしまう)
該当のソースコード
ルートディレクトリの.htaccess
<IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] RewriteCond %{HTTPS} !on RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L] RewriteCond %{HTTP_HOST} ^www.sample.com$ RewriteRule ^(.*)$ https://sample.com/$1 [R=301,L] RewriteCond %{REQUEST_FILENAME} index.(html|php) RewriteRule ^index.(html|php)$ / [R=301,L] RewriteRule ^(.*)/index.(html|php)$ /$1/ [R=301,L] </IfModule>
/shop/ディレクトリの.htaccess
<IfModule mod_rewrite.c> RewriteEngine On RewriteOptions Inherit RewriteBase /shop/ RewriteRule ^index.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] RewriteCond %{HTTPS} !on RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L] RewriteCond %{HTTP_HOST} ^www.sample.com$ RewriteRule ^(.*)$ https://sample.com/shop/$1 [R=301,L] RewriteCond %{REQUEST_FILENAME} index.(html|php) RewriteRule ^(.*)/index.(html|php)$ /$1/ [R=301,L] </IfModule>
参考までに、/wp/ディレクトリの.htaccess
<IfModule mod_rewrite.c> RewriteEngine On RewriteBase /wp/ RewriteRule ^index.html?$ / [R=301,L] RewriteRule ^index.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /wp/index.php [L] RewriteCond %{HTTPS} off RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R,L] </IfModule>
試したこと
Rewriteについて検索しながら細々と記述を変えてはテストしているのですが、
時々500エラーを出してしまいつつ、失敗が改善されない状態が続いています。
補足情報
ルートディレクトリの.htaccessには、アクセス制限の記述も入れています。
/wp/ディレクトリの.htaccessには、wordpressのログインURLにアクセスできるIPを制限する記述も入れています。
長くなりましたが、質問内容は以上となります。
改善策についてアドバイスをいただければ幸いです。
どうぞよろしくお願いいたします。
回答1件