Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/256.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
.htaccess在目录与php文件同名的情况下重写_Php_Apache_.htaccess_Mod Rewrite_Url Rewriting - Fatal编程技术网

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

.htaccess在目录与php文件同名的情况下重写,php,apache,.htaccess,mod-rewrite,url-rewriting,Php,Apache,.htaccess,Mod Rewrite,Url Rewriting,假设我有以下文件/文件夹: 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”扩

假设我有以下文件/文件夹:

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
/a.php
/B.php

由于某种原因,您给我的代码不起作用。相反,我使用了以下代码:RewriteEngine On directory slash Off RewriteCond%{REQUEST_FILENAME}(A | B)/$RewriteRule^(.*)/$$1 RewriteCond%{REQUEST_FILENAME}\.php-f RewriteRule^(.*$$1.php如何更改(A | B)的行以包含所有可能具有相同名称的文件/文件夹?