Apache在URL中重写字符串-障碍是“?"在查询中 [英] Apache rewrite string in URL - obstacle is "?" in query
问题描述
想要从给定的用户前缀("u-")重写URL,
Want to rewrite an URL with a given user-prefix ("u-") from
https://example.com/access/check?user=u-abc&pass=123
不带前缀的URL:
https://example.com/access/check?user=abc&pass=123
我尝试了一些规则,例如
I tried several rules, e.g
RewriteBase /
RewriteRule ^access/check?user=u-(.*)$ check?user=$1
我坚持使用?"
如果重写必须适用于略微相同的内容,但是没有?",则确实有效:
IF the rewrite had to apply to slightly the same, but without the "?", it indeed works:
https://example.com/access/checkuser=u-abc&pass=123
RewriteRule ^access/checkuser=u-(.*)$ checkuser=$1
并提供预期的结果(不带用户前缀"u-")
and provides the expected outcome (without the user-prefix "u-")
checkuser=abc&pass=123
我试图匹配?"和[?]或\ x3F,并按照 mod_rewrite.org ,但仍然没有成功.
I tried to match the "?" with [?] or \x3F, and applied the QSA flag as described on mod_rewrite.org , but still not succeeded.
推荐答案
The query string is not part of the RewriteRule
pattern
匹配什么?
- ...
- 如果要与主机名,端口或查询字符串匹配,请分别使用RewriteCond和%{HTTP_HOST},%{SERVER_PORT}或%{QUERY_STRING}变量.
因此,在您的情况下,您必须检查QUERY_STRING
并使用替换%1
代替$1
So in your case, you must check against QUERY_STRING
and use the replacement %1
instead of $1
RewriteCond %{QUERY_STRING} user=u-(.*)
RewriteRule ^access/check$ /access/check?user=%1 [L]
这篇关于Apache在URL中重写字符串-障碍是“?"在查询中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!