如何在 php 和 xampp 中从Request_URI中删除文件夹?



我有要索引的网址.php像这样http://localhost/exercise/

当我打电话时

return var_dump(
trim(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH), '/')
);

我在 xampp 的 htdocs 中exercise项目文件夹。

在网址上http://localhost/exercise/sd/ds我得到exercise/sd/ds

如何在request_uri中删除该文件夹名称?或任何其他(如果有的话(文件夹,如果这个php脚本嵌套在很多文件夹中。

如何从脚本所在的这一点开始Request_URI?

发表评论后,您可以使用 .htacces-file 来解决您的问题。.htaccess 必须位于与脚本相同的文件夹中。

.htaccess:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} ^(.*)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* /exercise/index.php?url=%1 [QSA]
</IfModule>

索引.php:

$url = $_GET['url'];

最新更新