为什么我的rewriterrule从替换字符串而不是uri中捕获部分?


Why does my rewriterule captures parts from the substitution string instead of the uri

给定此url:

http://test.com/myfile/product/1

和以下rewriterrule:

RewriteRule ([^/.]+)/?(.*) app/$1.php?$2

我希望url变成:

http://test.com/app/myfile.php?product/1

,当我使用一个在线的htaccess测试器。但是在我的本地开发环境中,我得到这个:

请求的URL/app/app.php在此服务器上找不到。

为什么?这不可能是对的,对吧?我怀疑这是由我的设置(docker容器和dinghy-http-proxy)引起的错误,但由于我对这种重写不熟悉,我不确定。

试试这个:

RewriteRule ^([^/.]+)/?(.*) app/$1.php?$2

问题是regex可以匹配路径字符串中的任何位置,并且由于/是可选的,因此结果不太可能是您想要的。

同时,确保你没有多个重写规则,默认情况下它们都会被处理!