重写以追加到查询字符串 [英] Rewrite to append to query string

查看:70
本文介绍了重写以追加到查询字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不明白为什么我总是在重写规则方面遇到如此大的问题,但是我只是想在查询字符串存在的情况下追加它,而在不存在的情况下添加一个?.我实际上并不在乎浏览器中是否更改了URL,它只需要加载正确的目标页面即可.

I don't understand why I always have such a massive problem with rewrite rules, but I simply want to append to the query string if it exists and add a ? if it does not. I actually don't care if the URL is changed in the browser or not -- it just has to load the correct target page.

RewriteRule /cia16(.*)\?(.*) /cia$1?$2&CIA=16
RewriteRule /cia16(.*) /cia/$1?CIA=16

如果我转到/cia16/steps.php?page=1,它实际上会被重写为/cia/steps.php?CIA=16-看来,出于重写的目的,甚至不认为查询字符串部分是URL的一部分.

If I go to /cia16/steps.php?page=1 it actually gets rewritten to /cia/steps.php?CIA=16 -- that is it seems accept the query string part is not even considered part of the URL for the purposes of the rewrite.

我该怎么做才能使重写与现有查询字符串一起正常工作?

What do I have to do to get the rewrite to work properly with an existing query string?

推荐答案

您无法与RewriteRule中的查询字符串匹配,需要与RewriteCond中的%{QUERY_STRING}变量匹配.但是,如果只想追加查询字符串,则可以使用QSA标志:

You can't match against the query string within a RewriteRule, you need to match against the %{QUERY_STRING} variable in a RewriteCond. However, if you want to just append the query string, you can just use the QSA flag:

RewriteRule /cia16(.*) /cia/$1?CIA=16 [QSA]

URI:/cia16/steps.php?page=1将被重写为/cia/steps.php?CIA=16&page=1.如果出于某种原因,您需要先page=1 ,然后可以执行以下操作:

The URI: /cia16/steps.php?page=1 would get rewritten to /cia/steps.php?CIA=16&page=1. If for some reason, you need the page=1 before the CIA=16, then you can do something like this:

RewriteRule /cia16(.*) /cia/$1?%{QUERY_STRING}&CIA=16

这篇关于重写以追加到查询字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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