如何在XAMPP中访问虚拟主机中的DocumentRoot之外的文件


How to access files outside the DocumentRoot in a VirtualHost in XAMPP?

我在Windows 7中配置了一个虚拟主机。项目位于C:'project,结构如下:

project
  'cache
  'configs
  'htdocs
    'css
    'images
    'js
    '.htaccess
    'index.php
  'includes
    'setup.php
    'en.php
  'lib
  'templates
  'templates_c

在我的httpd-vhosts.conf,我创建了一个虚拟主机:

 <VirtualHost *:80>
    DocumentRoot "C:/project/htdocs"
    ServerName project.dev
    <Directory "C:/project/htdocs">
        Options Indexes FollowSymLinks ExecCGI Includes
        AllowOverride All
        Order allow,deny
        Allow from all
        Require all granted
    </Directory>
</VirtualHost>

C:'Windows'System32'drivers'etc'hosts中加入127.0.0.1 project.dev

问题是,我希望htdocshttpd将服务文件的目录,但我想包括,与PHP,文件,例如,位于includes目录。

我该如何解决这个问题?我已经尝试了很多解决方案,从$_SERVER['DOCUMENT_ROOT']到Apache别名和.htaccess调整,但到目前为止还没有工作。一定有简单的解决办法。也许我没有完全正确地理解DocumentRoot的概念。我只是想模拟典型的服务器文件夹public_html/www/htdocs,同时保持重要文件不在浏览器/用户范围内。

这是我从httpd-vhosts.conf中获取的VHost。我做的唯一额外配置是绕过我正在点击的403:

<VirtualHost *:80>
    ServerName "Markdown.loc"
    ServerAlias "www.Markdown.loc"
    DocumentRoot "C:'INTERNAL'PHP'Markdown"
    <Directory "C:'INTERNAL'PHP'Markdown">
        Options +Indexes
        AllowOverride All
    </Directory>
</VirtualHost>

我所有的其他vhost看起来像这样:

<VirtualHost *:80>
    DocumentRoot "C:/xampp/htdocs/somesite.loc"
    ServerName somesite.loc
    ServerAlias www.somesite.loc
</VirtualHost>

如果你只是想从目录中包含一些与你的htdocs相同级别的东西,include("../includes/somefile.php")应该工作得很好。

如果我弄错了你的问题,告诉我,我会尽量帮助你。

在虚拟主机或。htaccess中设置包含路径:

php_value include_path ".;c:/project"