简单的动态 mod_rewrite
是的,这很简单,但是我能让正则表达式起作用吗?显然不是。
我需要变成
http://example.com/search.php?widget_id=X4234-000
我
http://example.com/show.php?noddy_id=X4234-000
尝试过的人,
RewriteRule search\.php\?widget_id=(.+?)$ show.php?noddy_id=%1
而且
RewriteRule search\.php\?widget_id=(.+?)$ show.php?noddy_id=$1
(向菲尔斯博士致敬!)
但没有成功。有人指点一下吗?
Yes, it's trivial, but can I get the regular expressions to work? Plainly not.
I need to turn
http://example.com/search.php?widget_id=X4234-000
into
http://example.com/show.php?noddy_id=X4234-000
I tried,
RewriteRule search\.php\?widget_id=(.+?)$ show.php?noddy_id=%1
and also
RewriteRule search\.php\?widget_id=(.+?)$ show.php?noddy_id=$1
(hat tip to Dr Fells!)
But no success. Any pointers anyone?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您无法将查询字符串与 RewriteRule 匹配。为此,请使用 RewriteCond 指令:(
顺便说一句,%x 用于重写条件中的组匹配,$1 用于重写规则)
如果您想在 QueryString 中保留其他变量,最终您可以将 QSA 添加到标志中。
You can't match the query string with the RewriteRule. For that use the RewriteCond directive :
(BTW, %x are for group matches in rewrite conds and $1 in rewrite rules)
Eventually you can add QSA to the flags if you have additional variables in the QueryString you want to keep.
确实很简单! %1 应为 1 美元
Simple indeed! %1 should be $1