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=$ last;

5、www.myweb.com/admin/ 下跳转为www.myweb.com/admin/index.php?s=

if (!-e $request_filename){
rewrite ^/admin/(.*)$ /admin/index.php?s=/$ last;
}

6、在后面添加/index.php?s=

if (!-e $request_filename){
rewrite ^/(.*)$ /index.php?s=/$ last;
}

7、www.myweb.com/xinwen/123.html  等xinwen下面数字+html的链接跳转为404

rewrite ^/xinwen/([-]+)\.html$ /.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/.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/\-([-]+)\-([-]+)/(.*)$ http://www.myweb.com/news/activies/$3 permanent;

14、nginx多条件重定向rewrite

如果需要打开带有play的链接就跳转到play,不过/admin/play这个不能跳转

if ($request_filename ~ (.*)/play){ set $payvar '';}
if ($request_filename ~ (.*)/admin){ set $payvar '';}
if ($payvar ~ ''){
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常用rewrite跳转重定向实例的更多相关文章

  1. Nginx 转发页面跳转重定向

    简介 Nginx在反向代理过程中,通过重定向跳转时会找不到URL.是因为经常没有配置Host header 的端口,需要如下标红部分一样配置端口号. 只添加Host重定向之后,就会没有端口号. 方案 ...

  2. Nginx 实现 Rewrite 跳转

    文章原创于公众号:程序猿周先森.本平台不定时更新,喜欢我的文章,欢迎关注我的微信公众号. 上一篇文章对Nginx的Location配置进行了讲解,本篇主要对于Nginx中的Rewrite跳转进行讲解. ...

  3. nginx 配置 rewrite 跳转

    在访问 test.com 网站时,会自动跳转到 www.test.com ,这是因为该网站做了 URL rewrite 重定向,一般网页重定向跳转分为两种,301 和 302 :301,302 都是H ...

  4. nginx 域名rewrite跳转

    转自:http://blog.csdn.net/xingfujie/article/details/7337832 需求:nginx规则,所有对OA.bccom.info的访问,redirect到uc ...

  5. Nginx常用Rewrite伪静态法则

    信赖此刻大部门用Linux VPS的伴侣都在利用这个敏捷传布的Nginx,本日就清算一下最常见的PHP法式的Rewrite(伪静态法则). Wordpress: location / {index i ...

  6. Nginx常用Rewrite(伪静态规则)WordPress/PHPCMS/ECSHOP/ShopEX/SaBlog/Discuz/DiscuzX/PHPWind/Typecho/DEDECMS

    目前已收集Wordpress.Wordpress二级目录.PHPCMS.ECSHOP.ShopEX.SaBlog.Discuz.Discuz X.PHPWind.Typecho.DEDECMS: Wo ...

  7. nginx的rewrite跳转

    Rewrite标记flag

  8. think PHP5中,模板、控制器、JavaScript的url跳转重定向方法

    php控制器中的跳转: 1, header()函数是PHP中进行页面跳转的一种十分简单的方法.主要功能是将HTTP协议标头(header)输出到浏览器. header("Location: ...

  9. JS实现页面跳转重定向的几种方式

    1.重定向 <script language="javascript"type="text/javascript">  window.locatio ...

随机推荐

  1. ViewPager的使用方法

    首先是 导入jar包   下载地址:android-support-v4.jar 布局文件里添加viewPager布局 [html] view plaincopy <android.suppor ...

  2. UIScrollView 实现比例缩放

    #import "RootViewController.h" @interface RootViewController ()<UIScrollViewDelegate> ...

  3. UTF8转unicode说明

    1.最新版iconv中的char *encTo = "UNICODE//IGNORE"; 是没有这个字符串的,它里面有UNICODELITTLE 和 UNICODEBIG 而且是没 ...

  4. Mongo client - cross-platform MongoDB management tool

    Mongo client for Ubuntu or Windows http://robomongo.org/download.html

  5. Delphi xe6 android Popup控件的使用

    1.拖放Label.button和popup控件到form 2.在structure将button1和label1拖到popup1上,然后调整布局就可以 Popup有几个重要的属性: 1.Placem ...

  6. AU3获取系统激活信息

    If IsActivated() = False Then ;InstallProductKey($OSkey) ; installs a product key and also activates ...

  7. Gazebo学习随记4 Actor: 该配合你的演出我视而不见

    在Gazebo仿真中,除了模型model外,还有一种和model并列的类型——actor. 相比于model受物理引擎的作用,actor不受重力等等的影响,可以按照设定的运动轨迹进行运动. <s ...

  8. Weekly Contest 114

    955. Delete Columns to Make Sorted II We are given an array A of N lowercase letter strings, all of ...

  9. 转载 【Linux】Linux中常用操作命令

    [Linux]Linux中常用操作命令     https://www.cnblogs.com/laov/p/3541414.html#vim   Linux简介及Ubuntu安装 常见指令 系统管理 ...

  10. 区块链中的密码学(-)区块链中运用最广的散列算法-SHA256算法分析与实现

    在很多技术人员的眼中,区块链并不是一种新的技术,而是过去很多年计算机技术的组合运用.而在这个方方面面技术的运用上,基于密码学的加密算法可以说是区块链各种特点得以表现的根本,一旦目前使用的加密算法被证实 ...