我可以显示 url 目录名称吗

Can i display url Directory name

请帮忙。 我的网站有错误,找不到页面。如果搜索 http://example.com/example。 我怎样才能像这样在我的错误页面中显示? "example not found" 或者,如果有人搜索,http://example.com/test 我怎样才能像这样在我的错误页面中显示一条消息? "test not found"

你可以提取 URL path 这样的东西

<?php
//http://example.com/example
$path = trim(parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH), "/");
echo htmlspecialchars($path) . " not found";
//will output "example not found";

如果您只需要提取路径的第一个目录

$firstDirectory = explode("/", $path)[0];