获取index.php脚本为Php的文件夹 [英] Get the Folder in which the index.php script is Php

查看:181
本文介绍了获取index.php脚本为Php的文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 AltoRouter 来匹配我的php应用程序的路由。显然,即使调用 index.php ,如果应用程序不在域根目录中,您也必须设置 $ router-> setBasePath( / path / to / script);

I am using AltoRouter to match routes for my php app. Apparently even if index.php is called, if the app is not in the domain root, you have to set $router->setBasePath("/path/to/script");

我需要一个收集子文件夹的函数(如果app在子文件夹中)。例如,路径是 / dir ,有人打电话给 www.domain.com/dir ,我知道它的 / dir 并调用 $ router-> setBasePath( / dir);

I need a function that collect the subfolder(if app is in subfolder).Eg if path is /dir and someone calls www.domain.com/dir, i can know its /dir and call $router->setBasePath("/dir");

推荐答案

您可以在.htaccess中使用以下规则:

You can use this rule in your .htaccess:

RewriteEngine On

RewriteCond $0#%{REQUEST_URI} ^([^#]*)#(.*)\1$
RewriteRule ^.*$ - [E=BASE:%2]

这会将`$ {ENV:BASE}设置为该.htaccess所在的任何子目录。

This will set `${ENV:BASE}" to whatever sub-directory this .htaccess is residing in.

然后在PHP内可以使用:

Then inside PHP you can use:

$_SERVER["BASE"]

这将设置为 / dir / 如果.htaccess位于 / dir1 / 中。

which will be set to /dir/ if .htaccess is in /dir1/.

这篇关于获取index.php脚本为Php的文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆