简体   繁体   English

这个Apache重写是什么意思?

[英]What does this apache rewrite means?

RewriteCond %{QUERY_STRING}    (.*)\?mem=stats$
RewriteRule  ^/(.*)$           http://X.X.X.X/$1?%1 [P,L]

If the request is /asdf?mem=stats , will it rewrite to /asdf?mem=stats?asdf ? 如果请求是/asdf?mem=stats ,它将重写为/asdf?mem=stats?asdf吗?

since $1 is asdf?mem=stats and %1 is asdf ??? 因为$1asdf?mem=stats%1asdf ???

The %{QUERY_STRING} variable contains the query string without the leading ? %{QUERY_STRING}变量包含查询字符串,但不包含前导? (or anything before it), so %1 will never contain part of the request before query string. (或其之前的任何内容),因此%1绝不会在查询字符串之前包含请求的一部分。

If you enable mod_rewrite logging by adding LogLevel rewrite:trace6 to your VirtualHost configuration, you will see this for your RewriteCond and /asdf?mem=stats request: 如果通过在VirtualHost配置中添加LogLevel rewrite:trace6来启用mod_rewrite日志记录,您将在RewriteCond和/asdf?mem=stats请求中看到以下内容:

... RewriteCond: input='mem=stats' pattern='(.*)\\?mem=stats$' => not-matched

Also, in your RewriteRule , pattern will be matched against the part of the URL after the hostname and port, and before the query string. 另外,在您的RewriteRule ,模式将与主机名和端口之后,查询字符串之前的URL部分匹配。 Therefore $1 will, even on wildcard match, not contain the query string part of the request. 因此,即使通配符匹配, $1也将不包含请求的查询字符串部分。 You can see that in log as: 您可以在日志中看到以下内容:

... applying pattern '^/(.*)$' to uri '/asdf' 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM