.htaccess 重写在目录与 PHP 文件同名的情况下


.htaccess rewrite in the case of directories having the same name as php files

假设我有这些文件/文件夹:

index.php
A.php
B.php
/A
  E.php
/B
  F.php
C.php
/D

假设我通过/site/访问页面。我想重写 URL 以执行这些任务:

/site/A -> /site/A.php
/site/B -> /site/B.php
/site/index -> /site/index.php
/site/A/F?id=828 -> /site/A/F.php?id=828

我还想在完成后屏蔽".php"扩展。如何以这种方式重写 URL?我看了这个问题,但我仍然不明白它是如何做到的。

尝试这样的事情:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ /$1.php [L]

您链接的问题进行了检查,以确保请求不是现有文件或目录。但这会中断,因为您有一个目录/A//B/。所以你只需要检查是否存在一个 /A.php/B.php .

相关文章: