URL 没有按预期在 apache 中重写 XAMPP

URL not re-writing as expected in apache XAMPP

请求的url是http://localhost/views/items?item=abc我想改写成http://localhost/views/myfile.php?reqtype=items&item=abc请注意查询前url的最后一个关键字items我要移动到查询部分 reqtype=items 得到这个我在 .htaccess

中写了下面的代码
RewriteEngine On
RewriteCond   %{QUERY_STRING}           ^(.*)$
RewriteRule   ^views/(.*)$          views/myfile.php?reqtype=&%1 [L,NE]

当我测试 here 通过直接粘贴到浏览器中验证其输出(来自此 link)时,此代码运行良好,因为 URL 运行良好。但是 xampp(我的版本是 7.1.28)它不工作。请记住 url-重写适用于其他类型的条件(意味着 apache 配置正确且有效)但这个特定示例不起作用,任何解决方案将不胜感激,谢谢。

您能否尝试使用显示的示例进行以下、编写和测试。请确保在测试 URL 之前清除浏览器缓存。请注意,这里的条件 RewriteCond %{ENV:REDIRECT_STATUS} ^$ 对于停止循环非常重要,否则它将继续重定向。我已经通过 curl 命令检查了这些规则,它们工作正常。

RewriteEngine ON
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{THE_REQUEST} \s/views/(items)\?([^\s]*)\s [NC]
RewriteRule ^(.*)$ views/myfile.php?reqtype=%1&%2 [NE,L]