.htaccessでの内部転送がうまくいきません

前提

XServerのに以下のようなディレクトリを構成しています。

public_html ┬ production ┬ index.html │ ├ service.html │ ├ favicon.ico │ ├ style.css │ ├ images │ ├ js │ ├ font │ └ css │ ├ staging ─ index.html │ └ .htaccess

.htaccessには以下のように記載しています。

RewriteEngine On RewriteCond %{HTTPS} !on RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L] RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC] RewriteRule ^(.*)$ https://%1/$1 [R=301,L] RewriteCond %{THE_REQUEST} ^.*/index.(html|php) RewriteRule ^(.*)index.(html|php)$ https://%{HTTP_HOST}/$1 [R=301,L] RewriteCond %{REQUEST_URI} !^/staging/ RewriteRule ^(.*)$ /production/$1 [L]

実現したいこと

  • https://~~~.com/~~~にアクセスした際にproduction配下のファイルを表示(URLはそのまま)したい
    • 例えば、https://~~~.comにアクセス → production/index.htmlの内容を表示
    • 例えば、https://~~~.com/service.htmlにアクセス → production/service.htmlの内容を表示
  • https://~~~.com/staging/~~~にアクセスした際にstaging配下のファイルを表示したい
    • 例えば、https://~~~.com/stagingにアクセス → staging/index.htmlの内容を表示
    • 例えば、staging配下をproduction配下のファイル構成と同じにした場合、https://~~~.com/staging/service.htmlにアクセス → staging/service.htmlの内容を表示

発生している問題・エラーメッセージ

stagingの方はアクセス可能だが、productionのほうはinternal errorになる。

試したこと

RewriteRule ^(.*)$ /production/$1 [L]RewriteRule ^(.*)$ /staging/$1 [L]に書き換えてhttps://~~~.comにアクセスすると staging/index.htmlが表示された。

コメントを投稿

0 コメント