Biz*_*rre 4 cookies redirect nginx query-string
我正在寻找的是nginx检测到url具有查询字符串变量cid的能力.
例如www.adomain.com/froggy?cid=12&as=false(查询字符串可以独奏或与其他人混合,cid不一定是查询字符串中的第一个变量)
如果检测到cid,它必须发送一个带有变量tmp_cid的set cookie标头,为它提供从cid查询字符串变量中获取的值.
然后它必须发送301重定向以将用户发送到它所带来的相同URL但没有cid查询字符串变量,因此使用上面的示例url,它将重定向到www.adomain.com/froggy?as=假
我希望这是有道理的.
小智 9
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;
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4464 次 |
| 最近记录: |