nginx带参数跳转
发表于:2026-10-31 作者:千家信息网编辑
千家信息网最后更新 2026年10月31日,原链接:https://www.baidu.com/benefit_detail?slug=bankofchina-20170320目标链接:https://www.test.cn/boc locat
千家信息网最后更新 2026年10月31日nginx带参数跳转
原链接:https://www.baidu.com/benefit_detail?slug=bankofchina-20170320目标链接:https://www.test.cn/boc location ~ /benefit_detail { if ($args ~* "slug=bankofchina-20170320") { rewrite ^/benefit_detail /boc? permanent; } try_files $uri $uri/ /index.php?$query_string; }常见跳转事例:1,将www.myweb.com/connect 跳转到connect.myweb.comrewrite ^/connect$ http://connect.myweb.com permanent;rewrite ^/connect/(.*)$ http://connect.myweb.com/$1 permanent;2,将connect.myweb.com 301跳转到www.myweb.com/connect/ if ($host = "connect.myweb.com"){rewrite ^/(.*)$ http://www.myweb.com/connect/$1 permanent; }3,myweb.com 跳转到www.myweb.comif ($host != 'www.myweb.com' ) { rewrite ^/(.*)$ http://www.myweb.com/$1 permanent; }4,www.myweb.com/category/123.html 跳转为 category/?cd=123rewrite "/category/(.*).html$" /category/?cd=$1 last;5,www.myweb.com/admin/ 下跳转为www.myweb.com/admin/index.php?s=if (!-e $request_filename){rewrite ^/admin/(.*)$ /admin/index.php?s=/$1 last; }6,在后面添加/index.php?s=if (!-e $request_filename){ rewrite ^/(.*)$ /index.php?s=/$1 last; }7,www.myweb.com/xinwen/123.html 等xinwen下面数字+html的链接跳转为404rewrite ^/xinwen/([0-9]+)\.html$ /404.html last;8,http://www.myweb.com/news/radaier.html 301跳转 http://www.myweb.com/strategy/rewrite ^/news/radaier.html http://www.myweb.com/strategy/ permanent;9,重定向 链接为404页面rewrite http://www.myweb.com/123/456.php /404.html last;10, 禁止htaccesslocation ~//.ht { deny all; }11, 可以禁止/data/下多级目录下.log.txt等请求;location ~ ^/data { deny all; }12, 禁止单个文件location ~ /www/log/123.log { deny all; }13, http://www.myweb.com/news/activies/2014-08-26/123.html 跳转为 http://www.myweb.com/news/activies/123.htmlrewrite ^/news/activies/2014\-([0-9]+)\-([0-9]+)/(.*)$ http://www.myweb.com/news/activies/$3 permanent;14,nginx多条件重定向rewrite如果需要打开带有play的链接就跳转到play,不过/admin/play这个不能跳转 if ($request_filename ~ (.*)/play){ set $payvar '1';} if ($request_filename ~ (.*)/admin){ set $payvar '0';} if ($payvar ~ '1'){ rewrite ^/ http://play.myweb.com/ break; }15,http://www.myweb.com/?gid=6 跳转为http://www.myweb.com/123.html if ($request_uri ~ "/\?gid\=6"){return http://www.myweb.com/123.html;}正则表达式匹配,其中:* ~ 为区分大小写匹配* ~* 为不区分大小写匹配* !~和!~*分别为区分大小写不匹配及不区分大小写不匹配文件及目录匹配,其中:* -f和!-f用来判断是否存在文件* -d和!-d用来判断是否存在目录* -e和!-e用来判断是否存在文件或目录* -x和!-x用来判断文件是否可执行flag标记有:* last 相当于Apache里的[L]标记,表示完成rewrite* break 终止匹配, 不再匹配后面的规则* redirect 返回302临时重定向 地址栏会显示跳转后的地址* permanent 返回301永久重定向 地址栏会显示跳转后的地址nginx各个内置变量含义请参考:https://blog.csdn.net/wanglei_storage/article/details/66004933【nginx try_files的理解】以 try_files $uri $uri/ /index.php; 为例,当用户请求 http://servers.blog.ustc.edu.cn/example 时,这里的 $uri 就是 /example。try_files 会到硬盘里尝试找这个文件。如果存在名为 /$root/example(其中 $root 是 WordPress 的安装目录)的文件,就直接把这个文件的内容发送给用户。显然,目录中没有叫 example 的文件。然后就看 $uri/,增加了一个 /,也就是看有没有名为 /$root/example/ 的目录。又找不到,就会 fall back 到 try_files 的最后一个选项 /index.php,发起一个内部 "子请求",也就是相当于nginx 发起一个 HTTP 请求到 http://servers.blog.ustc.edu.cn/index.php。这个请求会被 location~ \.php$ { ... } catch 住,也就是进入 FastCGI 的处理程序。而具体的 URI 及参数是在 REQUEST_URI 中传递给 FastCGI 和 WordPress 程序的,因此不受 URI 变化的影响[$request_uri解释]$request_uri就是完整url中刨去最前面$host剩下的部分,比如http://www.baidu.com/pan/beta/test1?fid=3这个url,去掉www.baidu.com剩下的就是了,日志里会看到打印出来的$request_uri其实是/pan/beta/test1?fid=3。如果只访问www.baidu.com,$request_uri里也会有个/的。if ($request_uri ~* "^/$") 表示url中只有域名,后面不跟任何东西,比如www.baidu.com。if ($request_uri ~* "test") 表示域名后面那串儿只要包含test这个关键词,就可匹配成功,比如www.baidu.com/pan/beta/test3if ($request_uri ~* "^/$"){ rewrite ^ http://kj.fnwtv.com/index.html permanent; }if ($request_uri !~* "^/$") { rewrite ^ http://www.fnwtv.com/ permanent; }【Nginx if 条件判断参考】https://www.cnblogs.com/saneri/p/6257188.htmllocation proxy_pass 后面的url 加与不加/的区别参考:https://blog.51cto.com/huangzp/1954575
文件
目录
链接
地址
大小
也就是
就是
参考
域名
条件
标记
用户
程序
参数
成功
东西
串儿
事例
关键
关键词
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
百单网互联网科技有限公司
互联网是第几次科技革命的成果
互联网科技保险
科技互联网政务服务
金融科技创新监管互联网金融
互联网科技公司电话
远信互联网科技
互联网科技视频
互联网金融科技委员会
汽车互联网创新科技园
中国航天科技大学国际工业互联网
链环科技传统企业怎么转型互联网
科技互联网的核心竞争力
每天都有哪些好的互联网科技
中天科技中国工业互联网
平安好医生打造互联网科技医疗
科技互联网专业务虚会材料
青岛互联网科技园
中国主要互联网科技公司
每日互联网科技新闻
互联网电商科技
互联网品科技
西安互联网科技
农村开互联网科技讲堂
互联网科技项目计划书材料类
江阴互联网智能科技产品进口
崇明区互联网教育科技售后服务
互联网科技和信息
上海同邻互联网科技有限公司规模
互联网科技和医药行业