1、将www.myweb.com/connect 跳转到connect.myweb.com

rewrite ^/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.com

if ($host != 'www.myweb.com') {

rewrite^/(.*)$ http://www.myweb.com/$1 permanent;}

4、www.myweb.com/category/123.html 跳转为 category/?cd=123

rewrite "/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的链接跳转为404

rewrite ^/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、禁止htaccess

location ~//.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.html

rewrite ^/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永久重定向 地址栏会显示跳转后的地址

index.php s 1 last,Nginx常用rewrite跳转重定向实例相关推荐

  1. Nginx常用rewrite跳转重定向实例

    1.将www.myweb.com/connect 跳转到connect.myweb.com rewrite ^/connect$ http://connect.myweb.com permanent; ...

  2. index.php?s=$1,thinkphp nginx配置rewrite,地址会多出个.php

    thinkphp nginx配置rewrite,地址会多出个.php ,http://localhost:7080/.php?m=... nginx配置文件 server { listen 80; # ...

  3. Nginx及rewrite跳转

    文章目录 一.Nginx常见模块 二.常用的Nginx 正则表达式 三.location概述 3.1 location 分类 3.2 location 常用的匹配规则 3.3 location 优先级 ...

  4. Nginx伪静态配置和常用Rewrite伪静态规则集锦

    伪静态是一种可以把文件后缀改成任何可能的一种方法,如果我想把php文件伪静态成html文件,这种相当简单的,下面我来介绍nginx 伪静态配置方法 nginx里使用伪静态是直接在nginx.conf ...

  5. 前端开发掌握nginx常用功能之rewrite

    上一篇博文对nginx最常用功能的server及location的匹配规则进行了讲解,这也是nginx实现控制访问和反向代理的基础.掌握请求的匹配规则算是对nginx有了入门,但是这些往往还是不能满足 ...

  6. Nginx之rewrite配置

    Rewtrite : 其主要目的是为了进行URL 重写,进行URL重定向.主要采用PCRE: Perl Compatible Regular Expressions(Perl兼容正则表达式语法)进行规 ...

  7. Nginx常用使用解读及配置

    概述 什么是 Nginx? Nginx (engine x) 是一款轻量级的 Web 服务器 .反向代理服务器及电子邮件(IMAP/POP3)代理服务器. 什么是反向代理? 反向代理(Reverse ...

  8. Nginx中rewrite的用法详解

    文章目录 一.rewrite简介 1.1 rewrite跳转场景 1.2 rewrite跳转实现过程 1.3 rewrite实际场景 1.4 nginx正则表达式 二.rewrite命令 2.1 re ...

  9. centos 7.6——Nginx中rewrite模块应用(location)——基于域名的跳转等

    centos 7.6--Nginx中rewrite模块应用(location)--基于域名的跳转等 文章目录 centos 7.6--Nginx中rewrite模块应用(location)--基于域名 ...

最新文章

  1. 【CV】吴恩达机器学习课程笔记第16章
  2. 偷懒日志 - 自动生成代码 - 第二步 生成POJO
  3. python打开摄像头获取图片_Python基于opencv调用摄像头获取个人图片的实现方法
  4. brew 安装mysql5.6_mac使用brew安装mysql的坑
  5. JavaScript基础09-day11【原型对象、toString()、垃圾回收、数组、数组字面量、数组方法】
  6. Jmeter连接Mysql
  7. 今日头条电脑版官方版_雷霆拯救电脑版-雷霆拯救pc版下载v4.0.9 官方版
  8. Redis企业级数据备份与恢复方案
  9. JavaWeb项目 打开首页就跳转debug模式的解决方法
  10. 公钥、私钥、数字证书的概念 (讲得很明吧,通俗易懂)
  11. SQL Server和Oracle数据库索引介绍
  12. 怎么下载linux历史文件,快速学习Linux-Linux历史
  13. matlab读取yuv420文件,基于matlab的YUV420播放器程序
  14. webSocket和http长连接短连接
  15. 绝对干货!百度文档 用python一键下载
  16. Luzj's ZTE Win版 终于开发完成
  17. Team Foundation Server 2013 with Update 3 Install LOG
  18. 组织架构与中台建设,回顾阿里小米京东美团四大商业巨头的战略变迁
  19. Android intent.Action 参数值及对应功能介绍(转)
  20. 谷歌Mediapipe运行环境配置

热门文章

  1. 【报告分享】食品饮料行业供应链发展与渠道变革趋势.pdf(附下载链接)
  2. 速成pytorch学习——10天.训练模型的3种方法
  3. 计算机视觉书籍学习记录——1最近点匹配
  4. 2022年,图机器学习Graph ML发展到哪了?
  5. Leetcode每日一题:203.remove-linked-list-elements(移除链表元素)
  6. 西瓜书+实战+吴恩达机器学习(十八)降维(主成分分析 PCA)
  7. Greenplum 行存、列存,堆表、AO表的原理和选择
  8. 《Java 8 in Action》Chapter 12:新的日期和时间API
  9. Android调用相册、相机(兼容6.0、7.0、8.0)
  10. Jmeter并发压测