使用 Apache mod_rewrite 重写多个变量的规则
我想知道如何将 www.site.com?lang=lv&type=1&mode=2
重写为 www.site.com/lv/1/2
代码> 使用 Apache mod_rewrite 选项。
I would like to know how can I rewrite www.site.com?lang=lv&type=1&mode=2
into www.site.com/lv/1/2
using Apache mod_rewrite options.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
假设您确实想将
/lv/1/2
重写为?lang=lv&type=1&mode=2
(我认为没有理由做相反的事情)并且没有其他重写处于活动状态,这应该可以解决问题:此外;如果您想将这些幻数包含在您的 URI 中,您最好将它们替换为更有用的信息。
编辑:如果这确实与您想要的相反,请参阅 Matt S 的回答。
Assuming that you actually want to rewrite
/lv/1/2
to?lang=lv&type=1&mode=2
(I see no reason to do the opposite) and that no other rewrites are active, this should do the trick:Also; you'd be better off replacing those magic numbers with more useful information if you want to include them in your URI.
Edit: If it really is the opposite you'd like to do, see the answer by Matt S.
基本重写:
编辑:更改重写标志以强制永久重定向
Basic rewrite:
Edit: Changed rewrite flags to force a permanent redirect
您需要分别处理 URI 路径和查询。如果参数以完全相同的顺序出现,您可以执行以下操作:
否则,您需要在使用此规则之前将它们按正确的顺序放置,或者一次获取每个参数。
You need to handle the URI path and query separately. If the parameters appear in that very same order, you can do this:
Otherwise you will need to put them in the right order before using this rule or take each parameter at a time.