duanfeng3879 2014-05-10 09:13
浏览 91
已采纳

访问localhost的Apache 2问题

This is my first post here and I hope I'm doing the right way.

I installed apache2 in my ubuntu 14.04 local machine for studying purposes and all my files are in my home public_html folder.

When I try to access a site like localhost/~{user}/test/index.php everything works fine, but when I try to access the same site with localhost/home/{user}/public_html/test/index.php I get the following error:

The requested URL /home/{user}/public_html/test/index.php was not found on this server.

Apache/2.4.7 (Ubuntu) Server at localhost Port 80

I tried to use:

$echo dirname(__FILE__);

But it returns /home/{user}/public_html/test.

So why can't I access the same file with both paths?

  • 写回答

1条回答 默认 最新

  • dqfwcj0030 2014-05-10 10:11
    关注

    Lets' consider the second URL:

    http://localhost**/home/user/test/index.php**
    

    If you look in Apache's configuration you will notice that there is a directive called "DocumentRoot". This directive specifies where apache will map the initial "/" in the URL to.

    So, let's say that the DocumentRoot is set to /var/www/htdocs. When you request the path /home/user/test/index.php it will actially go looking for .... /var/www/htdocs/home/user/test/index.php, which I'm assuming doesn't exist. See DocumentRoot

    Ok, so why does the first one work? Because of Apache's UserDir module. This little module checks the "/~user/test/index.php" part of the link. The tilde (~) is what does it :). It then maps /~user/ to /home/user/, thus Apache will look for the file at /home/user/test/index.php. Voilá.

    Hope this helps.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

悬赏问题

  • ¥15 怎么实现数组的循环累加,simulink
  • ¥15 51单片机最小开发板系统,想让寻迹小车在全检测到黑线(寻迹模块代码在第一块板子上)时蜂鸣器响(在第二块板子上)
  • ¥15 pbootcms多选调用成列表
  • ¥15 51单片机oled显示时钟
  • ¥15 小规模TSP问题的动态规划求解
  • ¥25 kubelet.service: Failed with result 'exit-code'.
  • ¥15 bitvise黑框内一键部署v2ray提示账户没有root怎么解决
  • ¥15 车型识别以及相似度匹配中细节特征提取以及图像模糊问题
  • ¥15 怎么用鸿蒙的ArkTs写出来啊
  • ¥30 websocket服务端多线程通信
手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部