如何重写“something/test?id=test”到“test.php?id=test”在 .htaccess 中
如何将 something/test?id=test
重写为 .htaccess
中的 test.php?id=test
RewriteRule ^v1/games/list?sortToken=(.*)$ /juicy.php?id=$1 [QSA,NC,L]
没有任何作用!
How to rewrite something/test?id=test
to test.php?id=test
in .htaccess
RewriteRule ^v1/games/list?sortToken=(.*)$ /juicy.php?id=$1 [QSA,NC,L]
Nothing works!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
RewriteRule
模式仅与 URL 路径匹配,这特别排除了查询字符串。要匹配查询字符串,您需要使用附加条件并与QUERY_STRING
服务器变量进行匹配。但是,问题中给出的示例与您的 < 隐含的重写有很大不同代码>RewriteRule尝试?
要重写此示例,您可以使用如下内容:
上面将在内部将
//test?id=test
重写为test.php?id=test
。默认情况下会传递查询字符串,因此这会匹配任何查询字符串。但是,要将
/v1/games/list?sortToken=
重写为/juicy.php?id=
(如您的“尝试”所暗示的那样) "),您需要执行类似以下操作:The
RewriteRule
pattern matches against the URL-path only, which notably excludes the query string. To match the query string you need to use an additional condition and match against theQUERY_STRING
server variable.However, the example given in the question is quite different to the rewrite implied by your
RewriteRule
attempt?To rewrite this example, you could use something like this:
The above will internally rewrite
/<something>/test?id=test
totest.php?id=test
. The query string is passed through by default, so this matches any query string.However, to rewrite
/v1/games/list?sortToken=<something>
to/juicy.php?id=<something>
(as implied by your "attempt"), you would need to do something like the following instead: