如何使用 .HTACCESS 重写子目录中的 PHP 个文件

How to rewrite PHP files in a subdirectory with .HTACCESS

我的 webroot 中有一个子目录,其中包含一些 PHP 文件(www/services/files.php)。

当前 url:http://example.com/index.php?pageID=services/myservice

我希望它是:http://example.com/services/myservice

我的代码:

RewriteRule ^([a-zA-Z0-9_-]+)$ index.php?pageID=/services [L,QSA]

你想让它显示为两个子文件夹,所以我将把这段代码用于那种类型的 URL 结构。使用 .* 太贪心了。

这将允许您使用 http://example.com/services/myservice

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/([^/]+)/?$ index.php?pageID=/ [L]