重定向%{QUERY_STRING}以友好的URL重定向、友好、QUERY_STRING、URL

由网友(卧听桃花雨)分享简介:我想补充(关于htaccess的)最后一个改进,那就是我想它重定向 /?MOD = INICIO 到 / INICIO 。所以,我想用下面的code做到这一点,但它使建筑的URL像这样 / INICIO?MOD = INICIO I'm trying to add one last improvement (reg...

我想补充(关于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.

阅读全文

相关推荐

最新文章