把search.php?type=let&letter=B 重定向到 let-B.html
我开始想当然的以为:
rewriteRule ^search\.php\?type=let&letter=([A-Z]+)$ let-$1.html [L]
这样就行了,可是大错特错了,mod_rewrite的rewriteRule只对请求里的path做处理,对于?后面的部分,单独处理,有个专门的变量%{QUERY_STRING}负责。
What is matched?
The Pattern will initially be matched against the part of the
URL after the hostname and port, and before the query string. If you wish
to match against the hostname, port, or query string, use a
RewriteCond with the
%{HTTP_HOST}, %{SERVER_PORT}, or
%{QUERY_STRING} variables respectively.
于是改成:
RewriteCond %{QUERY_STRING} ^type=([A-Za-z]+)&letter=([A-Za-z]+)
RewriteRule ^search.php?$ %1-%2.html [L]
这样之后就成功了。
[more..]