Apache RewriteRule QSA 什么意思

看到下面这段代码:

RewriteCond %{REQUEST_FILENAME} !-l

RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]



The RewriteRule basically means that if the request is done that matches ^(.+)$ (matches any URL ), it will be rewritten as index.php?url=$1 which means a request for ollewill be rewritten as index.php?url=olle.

QSA means that if there‘s a query string passed with the original URL, it will be appended to the rewrite (olle?p=1 will be rewritten as index.php?url=olle&p=1.

L means if the rule matches, don‘t process any more RewriteRules below this one.

 

参考:http://*.com/questions/12551382/what-does-1-qsa-l-mean-in-my-htaccess-file

QSA = Query String Append.

This rule appends the GET query string which results from the ReWrite rule to the initial GET query string sent by the browser. For example, take the following RewriteRule:

 

RewriteRule ^/product/([0-9]*)/?     /product.php?product_id=$1    [QSA]

This simply makes the product_id number look like a directory to the user. Now say that I have two different views of the page, view=short and view=long. For whatever reason, I don‘t want to make these views look like directories by using a RewriteRule. So I want to be able to do things like:

http://mysite.com/product/1351283/?view=short

Let‘s see how QSA works. With QSA, my final rewritten URL is

http://example.com/product.php?product_id=1351283&view=short

QSA has caused the RewriteEngine to append the existing query string (view=short) to the new query string (product_id=1351283). Without QSA, the existing query string is simply replaced by the new query string:

http://example.com/product.php?product_id=1351283

If you do much scripting with reliance on GET variables, it is virtually imperative that you enable the QSA flag on all of your RewriteRulesNOTE: I‘m not sure how this works with PHP‘s session identifiers, which can be passed in the URL as a GET variable instead of a session cookie. This would probably be useful to know.

参考:http://wiki.apache.org/httpd/RewriteFlags/QSA

Apache RewriteRule QSA 什么意思

上一篇:转:前端控制器是邪恶的么?


下一篇:在vSphere5.0虚拟机里的Ubuntu Server 32位安装JDK