全球主机交流论坛

标题: 请教一下nginx 的匹配 [打印本页]

作者: 潇洒哥er    时间: 2017-6-12 12:00
标题: 请教一下nginx 的匹配
比如我想对访问 http://xxx.com/admin/, http://xxx.com/admin/login.php, http://xxx.com/admin/index.php

admin 目录包括下面所有文件的访问都 跳转到一个神秘 的地址,nginx 应该怎么写规则。

目前是

location ^~ /admin/
{
      rewrite ^ http://example.com/new-address.html;
}

但只对访问  http://xxx.com/admin  这个地址有效,只要我访问admin 下面的任何文件都 直接弹 404 . 我想访问admin下面所有文件,反正 就是/admin/开头的都 直接跳转到神秘网址。 应该如何 设置呢。

各位大佬请支支招。

作者: cgs3238    时间: 2017-6-12 13:17
location /admin/
作者: 潇洒哥er    时间: 2017-6-12 14:04
cgs3238 发表于 2017-6-12 13:17
location /admin/

有这样改过了,无用。
作者: 潇洒哥er    时间: 2017-6-12 14:05
@小夜 求教一下小夜MM
作者: aboutyj    时间: 2017-6-12 16:53
试下在你location中加下面这段
  1. if($uri ~^/admin/(.*)$){
  2. rewrite ^ 你定义的跳转地址
  3. }
复制代码

作者: lijihede    时间: 2017-6-12 17:42
  1. location /admin
  2. {
  3.       return 301 http://example.com/new-address.html;
  4. }
复制代码


放在 location / 之前
作者: 潇洒哥er    时间: 2017-6-12 20:54
lijihede 发表于 2017-6-12 17:42
放在 location / 之前

有的,在最前面的




欢迎光临 全球主机交流论坛 (https://loc.010206.xyz/) Powered by Discuz! X3.4