8.26.2008

Apache Rewrite Rules

http://httpd.apache.org/docs/2.2/rewrite/

Rewrite很牛的说,很强大。
可以从
/a/b/c -> index.php?p1=a&p2=b&p3=c
/abc/index.php -> index.html
/a/b?c=www -> /a/b/www/index.html
二级域名的实现
还有很多,研究一下上面文档就行了

这次修改重写主要是实现
/old/index.php?app=what -> /new/what/index.php
憋了一上午,就是没看手册。。。。。。。菜鸟的本性显露无遗

下文来自官方手册:

Modifying the Query String

By default, the query string is passed through unchanged. You can, however, create URLs in the substitution string containing a query string part. Simply use a question mark inside the substitution string to indicate that the following text should be re-injected into the query string. When you want to erase an existing query string, end the substitution string with just a question mark. To combine new and old query strings, use the [QSA] flag.

也就是它根本不修改参数,必须加上?才能去掉参数
然后就是去掉"app=" 因为QUERY_STRING获得?后所有的,即app=what
通过下面方式解决
RewriteCond %{QUERY_STRING} app=(.*)$
RewriteRule old /new/%1/index.php? [R=301,L]

RTFM!!!!!!

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home