Php .htaccess目录结构的重写规则

Php .htaccess目录结构的重写规则,php,apache,.htaccess,mod-rewrite,url-rewriting,Php,Apache,.htaccess,Mod Rewrite,Url Rewriting,因此,我在仔细阅读stackoverflow,寻找PHP seo友好路径参数的答案,遇到了一些问题,但与我需要的完全不同。我确信我最大的问题是没有完全理解重写规则。无论如何,我需要的是: 1)我需要从所有页面中删除(.php) http://www.example.com/directory1/file1 <---- no .php http://www.example.com/directory1/file2 <---- no .php http://www.example

因此,我在仔细阅读stackoverflow,寻找PHP seo友好路径参数的答案,遇到了一些问题,但与我需要的完全不同。我确信我最大的问题是没有完全理解
重写规则
。无论如何,我需要的是:

1)我需要从所有页面中删除(.php)

http://www.example.com/directory1/file1   <---- no .php
http://www.example.com/directory1/file2   <---- no .php
http://www.example.com/anotherDirectory/file1   <---- no .php
希望有一个
$\u GET
。以下是目录结构:

/index.php 
/directory1/
      --file1.php?param1=$1&param2=$2&param3=$3
      --file2.php
/anotherDirectory/
      --file1.php
这就是我所拥有的(但不起作用,即不获取查询参数)

旁注:
1) 如何处理可选参数?与此类似,param1-3可能是可选的,或者只是param2-3可能是可选的


2) 我还需要为每个文件设置不同的规则吗?

您的问题到底是什么?@starkeen我如何编写
重写规则
以粗体完成任务。我还编辑了这个问题,希望它更有意义一些@这更清楚吗?
/index.php 
/directory1/
      --file1.php?param1=$1&param2=$2&param3=$3
      --file2.php
/anotherDirectory/
      --file1.php
 RewriteEngine On
 RewriteCond %{REQUEST_FILENAME} -f [OR]
 RewriteCond %{REQUEST_FILENAME} -l [OR]
 RewriteCond %{REQUEST_FILENAME} -d
 RewriteRule ^.*$ - [NC,L]
 RewriteRule ^([a-z-]+)$ index.php/directory1/file1.php?param=$1 [QSA,L]