nginx带参数跳转
发表于:2025-12-01 作者:千家信息网编辑
千家信息网最后更新 2025年12月01日,原链接:https://www.baidu.com/benefit_detail?slug=bankofchina-20170320目标链接:https://www.test.cn/boc locat
千家信息网最后更新 2025年12月01日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安全错误
数据库的锁怎样保障安全
在linux上编写数据库
广西智慧医养软件开发电话
网络安全相关的课题项目实现
计算机网络技术同步检测卷
电力信息网络安全述职
软件开发些什么比较好
梦幻西游手游服务器最多几人
游族网络技术美术开发工程师
软件开发工程师工作态度
连接64位数据库
内蒙古移动城管软件开发公司
陕西云广互联网科技有限公司
c语言开发内存数据库
bis医学数据库来源
如何提高节假日网络安全
枝江蓝润互联网科技
山东省高考录取数据库
网络安全总结会议纪要
sock5协议的代理服务器
数据库集群是否使用中间件
幼儿园网络安全宣讲绘画作品
打开服务器连接异常
车载网络技术现状及发展趋势
wow9.0 服务器选择
网络教育软件开发计划
网络安全宣传周先进个人事迹材料
基因的抑制剂数据库
数据库字段必填
软件开发如何防止侵权
东城区网络技术概况