LoginSignup
0
0

More than 3 years have passed since last update.

ApacheでAliasを切ったパス配下で、特定のエンドポイントだけを例外的に任意ローカルフォルダへマッピングする

Posted at

ApacheでAliasを切ったパス配下で、特定のエンドポイントだけを例外的に任意ローカルフォルダへマッピングする

Aliasのネスト的なアプローチがあるのかしらと思ったけど、できずに手こずったのでメモ。

調べたところ、RewriteRuleのリダイレクト記法において、ローカルファイル・ディクトリを指定し、かつそれが存在する場合は、HTTPリダイレクトでなくファイルマッピング的動作をする模様。
Aliasを既に使用している場合はRewriteに頼るほかないらしい。

要件例

  1. サイトのコンテンツの置き場所は基本的に/var/www/site1
  2. /special以下のURLのみ、/var/www/site2にコンテンツ配置
  3. 上記に加えて更に/special/randing.htmlのみ/var/www/randing.htmlを参照

設定例

/etc/httpd/conf/httpd.conf
#大元の設定
DocumentRoot /var/www/site1
Alias /special /var/www/site2

#追記
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/special/randing.html$
RewriteRule ^(.*)$ /var/www/randing.html [L]

#他の設定と干渉してしまう場合等あれば下記も追記
<Files /var/www/randing.html>
    Require all granted
</Files>

上記で/var/www/site2/randing.htmlではなく、/var/www/randing.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