重定向%{QUERY

编程入门 行业动态 更新时间:2024-10-18 03:34:59
本文介绍了重定向%{QUERY_STRING}以友好的URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想补充(关于htaccess的)最后一个改进,那就是我想它重定向 /?MOD = INICIO 到 / INICIO 。所以,我想用下面的code做到这一点,但它使建筑的URL像这样 / INICIO?MOD = INICIO

I'm trying to add one last improvement (regarding htaccess), and that is that I would like it to redirect /?mod=inicio to /inicio. So I'm trying to do it with the following code, but It keeps building the url like this /inicio?mod=inicio

RewriteCond %{QUERY_STRING} ^mod=([a-z]+)$ [NC] RewriteRule .* /%1 [L]

同样的事情额外的参数:从 / MOD = X&放大器;类型= YZ 到 / X / YZ ?

推荐答案

尝试这些规则来代替:

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /\?mod=([a-z]+)&type=([a-z\-]+) RewriteRule ^ /%1/%2? [L] RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /\?mod=([a-z]+)($|\ ) RewriteRule ^ /%1? [L]

关键是要匹配的实际要求,而不是URI,因为你的其他规则(从previous问题)会导致这些重写匹配,他们会互相冲突。另一个关键点是包括?在目标的结尾(例如: /%1 /%2? ),这使得它如此的查询字符串的没有得到追加的。

The key is to match against the actual request instead of the URI because your other rules (from your previous question) will cause these rewrites to match, they'll conflict with each other. The other key point is to include a ? at the end of the targets (e.g. /%1/%2?) which makes it so the query string doesn't get appended.

更多推荐

重定向%{QUERY

本文发布于:2023-11-01 12:56:47,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1549393.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:重定向   QUERY

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!