Get the Folder in which the index.php script is Php [closed]

北战南征 提交于 2019-12-11 13:26:19

问题


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");

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");


回答1:


You can use this rule in your .htaccess:

RewriteEngine On

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

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

Then inside PHP you can use:

$_SERVER["BASE"]

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



来源:https://stackoverflow.com/questions/25626375/get-the-folder-in-which-the-index-php-script-is-php

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!