首页 > 其他 > 详细

Apache RewriteRule QSA 什么意思

时间:2014-01-26 15:44:49      阅读:413      评论:0      收藏:0      [点我收藏+]

看到下面这段代码:

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://stackoverflow.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 什么意思

原文:http://www.cnblogs.com/youxin/p/3533909.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!