【问题标题】:Multiple DocumentRoot directives in ApacheApache 中的多个 DocumentRoot 指令
【发布时间】:2016-05-20 05:57:51
【问题描述】:

我的问题与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,但如果 VirtualHost 在当前 DocumentRoot 中失败,我不知道如何在此处查看。

再次,如果服务器无法在 .../example/html folder. 中找到某些内容,我希望服务器在公共文件夹中查找 Apache 是否支持这一点?

【问题讨论】:

  • 在所有重写规则的末尾,写上:RewriteCond %{REQUEST_FLENAME} !-f RewriteRule ^ /var/www/common/html%{REQUEST_URI} [L]
  • @hjpotter92 这正是我想要的。谢谢你喜欢的规则。您想将此评论添加为回复,以便我标记答案吗?

标签: apache virtualhost httpd.conf document-root


【解决方案1】:

comment 转换为回答:

在所有重写规则的最后,写上:

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

【讨论】:

    猜你喜欢
    • 2011-05-31
    • 2011-06-03
    • 1970-01-01
    • 2015-03-18
    • 1970-01-01
    • 1970-01-01
    • 2016-01-11
    • 2014-06-25
    • 1970-01-01
    相关资源
    最近更新 更多