dpdrtj1075 2013-03-03 03:05
浏览 153
已采纳

如何在XAMPP中的VirtualHost中访问DocumentRoot之外的文件?

I have a Virtual Host configured in Windows 7. The project is located in C:\project with the following structure:

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

In my httpd-vhosts.conf, I created a VirtualHost:

 <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>

And added 127.0.0.1 project.dev to the C:\Windows\System32\drivers\etc\hosts.

The problem is that I want the htdocs to be the directory from which httpd will serve files but I want to include, with PHP, files, for example, located in the includes directory.

How can I solve this problem? I already tried so many solutions from $_SERVER['DOCUMENT_ROOT'] to Apache Alias and .htaccess tweaking but none have worked so far. There must have be some easy solution. Maybe I'm not understanding quite correctly the concept of DocumentRoot. I just want to emulate the typical server folder public_html/www/htdocs while keeping important files out of the browser/user scope.

  • 写回答

2条回答 默认 最新

  • dongtao4890 2013-03-03 03:09
    关注

    This is a VHost I took from my httpd-vhosts.conf. The only extra configuration I made was to get around the 403 I was hitting:

    <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>
    

    All my other VHosts look like this:

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

    If you're simply looking to include something from a dir on the same level as your htdocs though, include("../includes/somefile.php") should work just fine.

    If I've got your problem wrong, let me know, and I'll try to help you more.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥50 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?