日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > Nginx >内容正文

Nginx

【Nginx】截取URL中某个参数Parameter

發布時間:2024/9/19 Nginx 73 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【Nginx】截取URL中某个参数Parameter 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

前言

  • nginx 1.15.11(下面的代碼在此版本測試通過)

截取URL中某個參數Parameter

假設,截取參數method的值。當method=autoGenerateIndex時,截取到autoGenerateIndex。

location ~* ^/test {#設置content typedefault_type text/html ;# HTTP Status Code 和 內容 if ($query_string ~ ".*(?:^|\?|&)method=(.+?)(?:(?:&.*)|$)") { return 200 "$1"; }return 200 "I'm sure it'll work out."; }
  • nginx 中可以使用正則表達式,比如:if ($query_string ~ "正則表達式") {...}。

    - ~:與指定正則表達式模式匹配時返回“真”,判斷匹配與否時區分字符大小寫; ~*:與指定正則表達式模式匹配時返回“真”,判斷匹配與否時不區分字符大小寫; !~:與指定正則表達式模式不匹配時返回“真”,判斷匹配與否時區分字符大小寫; !~*:與指定正則表達式模式不匹配時返回“真”,判斷匹配與否時不區分字符大小寫;
  • ? 當該字符緊跟在任何一個其他限制符 (*, +, ?, {n}, {n,}, {n,m}) 后面時,匹配模式是非貪婪的,比如(.+?)。

  • (?:pattern) 匹配 pattern 但不獲取匹配結果,比如(?:^|\?|&)、(?:(?:&.*)|$)。

  • (pattern) 匹配 pattern 并獲取這一匹配,比如(.+?)。獲取方式為:$1。

  • $ 匹配輸入字符串的結束位置。

當訪問如下地址時,看到:autoGenerateIndex
http://school-test.3jcf.com/test?method=autoGenerateIndex
http://school-test.3jcf.com/test?s=job&method=autoGenerateIndex
http://school-test.3jcf.com/test?method=autoGenerateIndex&s=job

當訪問如下地址時,看到:autoGenerateIndex is work
http://school-test.3jcf.com/test?method=autoGenerateIndex is work
http://school-test.3jcf.com/test?s=job&method=autoGenerateIndex is work
http://school-test.3jcf.com/test?method=autoGenerateIndex is work&s=job

當訪問如下地址時,看到:I’m sure it’ll work out.
http://school-test.3jcf.com/test?method=
http://school-test.3jcf.com/test?a=s

參考

https://www.cnblogs.com/songxingzhu/p/6382007.html
https://www.runoob.com/regexp/regexp-metachar.html
https://sayyy.blog.csdn.net/article/details/104989568

總結

以上是生活随笔為你收集整理的【Nginx】截取URL中某个参数Parameter的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。