Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/270.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 当使用apache mod_别名和mod_重写时,如何检测URI中的根文件夹?_Php_Apache_Mod Rewrite - Fatal编程技术网

Php 当使用apache mod_别名和mod_重写时,如何检测URI中的根文件夹?

Php 当使用apache mod_别名和mod_重写时,如何检测URI中的根文件夹?,php,apache,mod-rewrite,Php,Apache,Mod Rewrite,当使用apache mod_别名和mod_重写时,如何检测URI中的根文件夹 我有一个网站运行在文档根目录的子文件夹中,例如/var/www/this/an/other/dir,在这个文件夹中我有一个.ht\u访问文件,带有mod\u重写规则,可以将所有内容重定向到index.php # Do nothing if the file (s), link (l) or (d) exists RewriteCond %{REQUEST_FILENAME} -s [OR] RewriteCond %{

当使用apache mod_别名和mod_重写时,如何检测URI中的根文件夹

我有一个网站运行在文档根目录的子文件夹中,例如/var/www/this/an/other/dir,在这个文件夹中我有一个.ht\u访问文件,带有mod\u重写规则,可以将所有内容重定向到index.php

# Do nothing if the file (s), link (l) or (d) exists
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]

# Redirect everything else to index.php
RewriteRule ^.*$ index.php [E=PORT:%{SERVER_PORT},NC,L]`
我还设置了一个别名以便于访问

alias /foo /var/www/this/an/other/dir

现在,当我转到地址时,如何才能检测到/foo是我的URI的根文件夹?

我不太理解您的问题。
根文件夹总是相同的-
/
。无需确定。

如果您需要虚拟文档根目录-只需使用
dirname($\u SERVER[“SCRIPT\u FILENAME]”)

最简单的方法是直接在Apache中设置一个env变量:

SetEnv AliasRoot /foo
然后,您可以通过
$\u ENV
超全局访问它:

$root = $_ENV['AliasRoot'];

我认为在纯PHP中没有可靠的方法可以做到这一点。

尝试重写规则^(.*)$index.PHP?uri=$1[E=PORT:%{SERVER\u PORT},NC,L]@ITroubs uri已经可以通过请求访问。\u uri我想知道的是,当我在/foo/bar中时,我的index.PHP在/foo$\u SERVER[“SCRIPT\u FILENAME”]返回来自服务器而非服务器的路径uri@vdrmrt是的,
dirname($\u SERVER[“SCRIPT\u FILENAME”])
是您的虚拟文档根目录。所以我说。至于foo-我不知道你为什么需要它,但是你可以通过比较
SCRIPT\u FILENAME
DOCUMENT\u ROOT
来获得一些魔力
phpinfo(32)
可以给你一些提示。比较脚本文件名和文档根是不可靠的,因为你可以使用
Alias/foo/var/www/some/dir/bar/
,那么你就完蛋了。