我会建议你一个更好的解决方案。
RewriteEngine on
# dont rewrite for directories
RewriteCond %{REQUEST_FILENAME} !-d
# rewrite everything else to index.php
RewriteRule .* index.php [L]
现在您可以在 index.php 中使用该变量
$_SERVER['REQUEST_URI']
您可以阅读请求的文件
例子:
网址: http: //my-site.de/Archives
然后在请求变量中,您将拥有字符串“Archives”,现在您可以使用 strtolower 将字符串解析为小写(我更喜欢这个 .. 如果 uri 是通过驼峰式大小写调用的)
另一个例子:
网址: http: //my-site.de/Archives/Latest/Show
请求变量包含字符串“Archives/Latest/Show”
现在您可以使用该目录在服务器上的同一目录中查找文件或使用路径作为请求的参数。
以 PHP 结尾的解决方案在 php 中如下所示:
<?php
$requestedPath = $_SERVER['REQUEST_URI'];
if (substr(strtolower($requestedPath),-4) != '.php') {
$requestedPath .= '.php';
}
if (file_exists($requestedPath)) {
include_once($requestedPath);
}
?>