htaccess 使用多个正斜杠重写 URL

htaccess rewriting URLs with multiple forward slashes

正在尝试制定一套 .htaccess mod_rewrite 规则来设置这些链接:

domain.com/content-page
domain.com/region/another-page
domain.com/region/brand/more-content-here

获取文件:

domain.com/content-page.php
domain.com/region-another-page.php
domain.com/region-brand-more-content-here.php

其中'region'和'brand'以及页面名称都是variable/changeable.

到目前为止我有:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ .php [NC,C]
RewriteRule ([^/]+)/([^/]+) - [NC,L] 

这有效,但仅适用于一个正斜杠。如上所述,域之后的 URL 可能有 none,一个或两个正斜杠。没有任何运气试图扩展它来处理多个(或不)斜杠。

尝试:

RewriteEngine On

# pass through root
RewriteRUle ^(index\.php)?$ - [L]

# no more / so add extension
RewriteCond  !/
RewriteCond  !\.php$
RewriteCond ${REQUEST_FILEAME} !-f
RewriteRule ^(.*)$ /.php [L]

RewriteCond %{REQUEST_URI} !\.php$
RewriteRule ^(.*)/(.*)$ /- [L]