http://site1.bla.example.com,http://site2.bla.example.com和http://site2.bla.example.com都指向/var/www/html
,这是我的DocumentRoot。
鉴于以下目录结构,我希望http://site1.bla.example.com/files/somefile1.png返回somefile1.png
,http://site2.bla.example.com/files/somefile2.png返回somefile2.png
等。
/var/www/html/index.php
/var/www/files/site1/somefile1.png
/var/www/files/site2/somefile2.png
/var/www/files/site3/somefile3.png
这是如何实现的?以下是我未能成功的尝试。
<VirtualHost *:80>
ServerName example.com
ServerAlias *.bla.example.com
DocumentRoot /var/www/html
#This seems to work, but I wish to use regex
# Alias /files/site1 /var/www/files/site1
#This doesn't work
AliasMatch ^/files/(.+)$ /var/www/files/$1
<Directory "/var/www/html">
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(.+)\.bla\.example\.com [NC]
RewriteRule ^public/([^//]+)$ public/%1/$1 [NC,L]
</Directory>
</VirtualHost>