重定向%{QUERY_STRING}以友好的URL [英] Redirecting %{QUERY_STRING} to friendly url

查看:129
本文介绍了重定向%{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_STRING}以友好的URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆