Php 重写文件夹,使所有文件都以新的重写规则显示

Php 重写文件夹,使所有文件都以新的重写规则显示,php,mod-rewrite,Php,Mod Rewrite,有没有一种方法可以重写文件夹,使该文件夹下的所有文件都遵循相同的规则?例如: 如果我有一个包含5个php文件(a.php、b.php、c.php、d.php、index.php)的文件夹,我使用以下规则: RewriteRule ^products/storage/?$ /content/products/storage/index.php [QSA,L] 有没有一种方法可以让我访问所有要显示的文件,比如:site.com/products/apples/a.php、site.com/prod

有没有一种方法可以重写文件夹,使该文件夹下的所有文件都遵循相同的规则?例如:

如果我有一个包含5个php文件(a.php、b.php、c.php、d.php、index.php)的文件夹,我使用以下规则:

RewriteRule ^products/storage/?$ /content/products/storage/index.php [QSA,L]
有没有一种方法可以让我访问所有要显示的文件,比如:site.com/products/apples/a.php、site.com/products/apples/b.php等,而不必为每个文件编写规则

我尝试了以下方法,但不起作用

RewriteRule ^products/storage/?$ /content/products/storage/ [QSA,L]
我还需要它不覆盖我的其他规则,例如:

RewriteRule ^products/storage/?$ /content/products/storage/product-name1/ [QSA,L]
RewriteRule ^products/storage/?$ /content/products/storage/product-name2/ [QSA,L]

有什么想法吗?

您的问题是正则表达式末尾的尾随
$
。仅当完整URI
产品/存储
(带可选尾随斜杠)完全匹配时,才允许匹配。相反,请尝试以下操作并注意缺少尾随的
$
字符:

RewriteRule ^products/storage/? /content/products/storage/ [QSA,L]
这将匹配以产品/存储开头的任何内容(可选尾随斜杠)。或者,如果您想捕获并重用URI中紧随其后的
products/storage/
中的所有内容,您可以尝试:

RewriteRule ^products/storage(/?.+)?$ /content/products/storage$1 [QSA,L]

更新

如果您需要按照更新的问题建议保留其他
RewriteRule
s,您应该添加一个
RewriteCond
条件,如下所示:

RewriteCond !^products/storage/?$
RewriteRule ^products/storage(/?.+)?$ /content/products/storage$1 [QSA,L]

RewriteCond
告诉
RewriteRule
只有在条件不满足时才进行处理。

hmmm嗯,我现在遇到了一个问题,其他规则不起作用。例如,我重写了规则^products/storage/?$/content/products/storage/product-name1/[QSA,L]重写了规则^products/storage/?$/content/products/storage/product-name2/[QSA,L]现在,如果我添加你给我的规则,那么这些都不起作用。你需要在
重写规则
之前添加
RewriteCond
条件,以明确阻止它在满足这些条件时应用。。。这是您应该在问题中更新的信息