0
0

【.htaccess】ルート階層以外でルートパスを使う

Posted at

<< 問題 >>
公開中のサイトで、/test/のディレクトリにテストページを作成した。
画像・ファイルの読み込み、内部リンクがルートパス指定されていたためホームディレクトリを参照してしまっていた。

■ 実現したいこと

  • /test/ の配下でルートパス指定をしたときは /test/ をドキュメントルートとして読み込みたい
  • それ以外のルートパス指定ではホームディレクトリを参照したい

<< 解決 >>
下記をホームディレクトリの.htacessに追記する

Options +SymLinksIfOwnerMatch
RewriteBase /
RewriteCond %{HTTP_REFERER} /test/
RewriteCond %{REQUEST_URI} !/test/
RewriteRule ^(.*)$ test/$1 [L,R]

参考)https://www.gravity-works.jp/gravica/web/htaccess/004589.html

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