Apache 为什么不是';这不是url重写吗?简单的

Apache 为什么不是';这不是url重写吗?简单的,apache,mod-rewrite,Apache,Mod Rewrite,这是一个我正在尝试做的例子 把这个翻过来: http://example.com/products/ 为此: http://example.com/app.php?products http://example.com/app.php?products&foo=bar&boat=row 最后我还需要对查询的支持,例如: 这: 为此: http://example.com/app.php?products http://example.com/app.php?product

这是一个我正在尝试做的例子

把这个翻过来:

http://example.com/products/
为此:

http://example.com/app.php?products
http://example.com/app.php?products&foo=bar&boat=row
最后我还需要对查询的支持,例如:

这:

为此:

http://example.com/app.php?products
http://example.com/app.php?products&foo=bar&boat=row
这是我迄今为止的重写:

RewriteRule ^([A-Za-z0-9]+)/?\??([A-Za-z0-9\+=&]+)?$ app.php?$1&$2 [L]
这适用于我的前两个示例,但是第二个示例仅适用于类似url的url

http://example.com/products/foo=bar&boat=row

我需要有一个问号在那里,我想\??在我的重写中,应该这样做,但它没有,instad返回404。我做错了什么?谢谢。

查询字符串可以使用
QSA
标志追加,您无法在
重写规则中与查询字符串进行匹配。试试这个:

RewriteRule ^([A-Za-z0-9]+)/?$ app.php?$1 [L,QSA]

@安德鲁:你说得对,我需要一个
$
来表示结束,我会编辑我的答案