有没有一种方法可以使用htaccess的url重写功能,让它看起来像是在/public/some/folder
中有一个文件,而实际上它在/public
中。
例如,我在根文件夹中有index.php,我希望它是这样的,当我访问index.php时,它也可以在所有文件夹和子文件夹中表现为
当我执行index.php时,它也会在所有文件夹和子文件夹中执行
更新
请通过下面的示例来理解我的问题
index.php在root中,我在root中也有不同的文件夹所以当我通过浏览器访问index.php时,它也会在其他文件夹中执行
http://example.com/index.php
的行为也会像它在子文件夹中的一样
http://example.com/folder1/index.php
http://example.com/folder2/index.php
http://example.com/folder3/index.php
index.php
不在这些文件夹中,但它也必须在中同时执行
我认为通过这个例子不难理解。请相应地回答
我不确定我是否正确理解你。但无论如何,你都可以在.htaccess 中尝试类似的东西
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?page=$1 [L,QSA]
因此,在它之后,所有内容都将转到带有$_GET[page]参数的index.php。因此,例如www.mydomen.com/try/to/get/this将转到我们的index.php,在那里我们将获得$_get[page]="try/to/get/this"。如果你要对这个字符串使用爆炸,你可以为你的url编写任何你想要的规则。类似于您自己的URL管理器:)
示例:
将index.php和.htaccess放在根文件夹中在您的index.php:中
$urlArray = explode("/",$_GET['page']);
switch($urlArray[0]){
case "try":
include($_SERVER[DOCUMENT_ROOT]."/path/to/folder/what/you/need/my.php");
break;
case "another_url":
include($_SERVER[DOCUMENT_ROOT]."/another/path/to/folder/what/you/need/my_another.php");
break;
}
希望这是你所需要的。