Apache中的多个DocumentRoot指令

时间:2016-02-10 02:21:36

标签: apache virtualhost httpd.conf document-root

我的问题类似于this one,但有一个重要的区别。我希望能够在主DocumentRoot中查找失败的情况下提供文件,而不是取决于文件的路径。

在我的Apache服务器上,我希望能够为我的网站提供多个DocumentRoot指令。这样,如果它无法在主DocumentRoot文件夹中找到该文件,它可以查看另一个(公共)文件夹。这就是我的意思:

<VirtualHost *:80>
     DocumentRoot /var/www/example/html
     # insert additional document root here
     # DocumentRootAlias /var/www/common/html
     ServerName www.example.com
     ServerAlias example.co
</VirtualHost>

我已经将全局DocumentRoot设置为/ var / www / common / html,但如果它在当前的DocumentRoot中失败,我不知道如何在这里查看VirtualHost。

同样,我希望服务器查看公共文件夹,如果它找不到.../example/html folder.中的某些内容,Apache会支持吗?

1 个答案:

答案 0 :(得分:1)

  

comment转换为回答:

在所有重写规则结束时,请输入:

RewriteCond %{REQUEST_FLENAME} !-f 
RewriteRule ^ /var/www/common/html%{REQUEST_URI} [L]