Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何设置PHP脚本来接收对目录中不存在的目录的请求?_Php_Linux_Dreamhost - Fatal编程技术网

如何设置PHP脚本来接收对目录中不存在的目录的请求?

如何设置PHP脚本来接收对目录中不存在的目录的请求?,php,linux,dreamhost,Php,Linux,Dreamhost,比方说,如果我在服务器上的根目录中有一个dir目录,其中包含index.php文件,我可以设置调用该index.php以获得以下任何链接: https://example.com/dir/ https://example.com/dir/something https://example.com/dir/something_else 抱歉,我不知道如何调用它,但基本上是将URL的最后一段传递到index.php脚本中,该脚本位于example.com/dir/中 另外,我的网站托管在一个共享的

比方说,如果我在服务器上的根目录中有一个
dir
目录,其中包含
index.php
文件,我可以设置调用该
index.php
以获得以下任何链接:

https://example.com/dir/
https://example.com/dir/something
https://example.com/dir/something_else
抱歉,我不知道如何调用它,但基本上是将URL的最后一段传递到
index.php
脚本中,该脚本位于
example.com/dir/


另外,我的网站托管在一个共享的web托管平台上。

您可以通过创建一个.htaccess文件并加入以下内容来利用index.php,而不是在每个文件夹中都有一个index.php:

FallbackResource /index.php

然后,您可以解析
$\u服务器['REQUEST\u URI']
,并对其执行任何操作。

这听起来更像是一个Web服务器配置问题,而不是PHP问题。@Barmar:从本质上讲,这不是一个“问题”。我只是想看看我能不能做到。哦,那太酷了。我需要试试,谢谢。我假设我必须将
.htaccess
放入
/home/dir/
文件夹中,对吗?它在每台服务器上的工作方式不同,所以我不能肯定地回答这个问题。我怀疑答案是肯定的,不过……实际上,我使用
FallbackResource index.php向
dir
目录本身添加了一个
.htaccess
。(注意不要斜杠,否则Apache会失败,出现错误500。)然后在
index.php
中,我能够从
$\u服务器['REQUEST\u URI']
获取路径。我今天刚学到一些新东西。再次感谢你!