访问DocumentRoot之外的文件

时间:2015-07-04 15:02:08

标签: regex apache mod-rewrite mod-alias

http://site1.bla.example.comhttp://site2.bla.example.comhttp://site2.bla.example.com都指向/var/www/html,这是我的DocumentRoot。

鉴于以下目录结构,我希望http://site1.bla.example.com/files/somefile1.png返回somefile1.pnghttp://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>

0 个答案:

没有答案