English 中文(简体)
Nginx 301 redirect inc. set cookie
原标题:

what I m looking for is the ability for nginx to detect that a url has the query string variable cid.

for example www.adomain.com/froggy?cid=12&as=false (query string can be solo or mixed with others and cid is not necessarily the first variable in the query string)

If cid is detected, it must send out a set cookie header with the variable tmp_cid giving it the value it took from the cid query string variable.

It must then also send out a 301 redirect to send the user to the same url it came in on but without the cid query string variable, so with the above example url, it would redirect to www.adomain.com/froggy?as=false

I hope this makes sense.

问题回答
location / {

    set $cid   ;

    if ( $query_string ~ "(.*)cid=([0-9]+)(&?)(.*)" ) {
        set $args $1$4;
        set $cid $2;
    }

    if ( $args ~ (.+)&$ ) {
        set $args $1;
    }

    if ( $cid !=    ) {
        add_header Set-Cookie tmp_cid=$cid;
        rewrite ^(.*)$ $1 permanent;
    }

}




相关问题
How to suppress/remove PHP session cookie

I need to suppress an already set session cookie header, but I cannot find any way to do this. Why? I need to make an image, sent by a PHP script, cacheable by the end user; this image is used to ...

Remove Cookies from JS or CSS files

Bizarrely my javascript and css files have cookies (says Firebug). I use Zend Framework and I think it has to do with it. Could I change the .htaccess that CSS or JS files don t link to the ZF or is ...

httplib2, how to set more than one cookie?

As you are probably aware, more often than not, an HTTP server will send more than just a session_id cookie; however, httplib2 handles cookies with a dictionary, like this: response, content = http....

cookies control

what tool wold you recommend me to use in order to see what data are stored in my cookies while i m browsing the net. I m a beginner into webdev field(6 months php experience) and i m curious to see ...

热门标签