AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / user-46214

Bretticus's questions

Martin Hope
Bretticus
Asked: 2012-11-20 16:06:06 +0800 CST

nginx 和 try_files:在回退之前尝试重写命名位置

  • 0

我正在尝试网站切换。我们想通过使用 301 重定向来保留我们的外部链接。我在一个命名位置有一个冗长的重定向列表,类似于:

location @redirects {       
    rewrite ^/path/one.html$ http://www.ourdomain.tld/one-but-different permanent;
    rewrite ^/path/two.html$ http://www.ourdomain.tld/two-but-different permanent;
    rewrite ^/path/three.html$ http://www.ourdomain.tld/three-but-different permanent;
    rewrite ^/path/four.html$ http://www.ourdomain.tld/four-but-different permanent;
}

(请注意,尽管我的示例显示了一种模式,但实际上并不存在这种模式。换句话说,它们是一对一的重定向。)

我有一个 CMS Web 应用程序,我目前正在使用以下 try_files 语句(它一直在工作以回退到 index.php 脚本):

location / {
    try_files $uri $uri/ /index.php;
}

现在我正在尝试使用 try_files 来“查看”重定向命名位置并在回退到 index.php 之前处理重写。像这样:

location / {
    try_files @redirects $uri $uri/ /index.php;
}

但是,每次 CMS 处理 404 时都会触发回退。换句话说,如果我尝试http://www.ourdomain.tld/path/one.html,我会得到 CMS 的 404 页面而不是重定向!是否可以先“尝试”命名位置,或者命名位置是否必须作为后备位置?

我确定我做错了。但是,有人可以指出我正确的方向吗?

nginx/1.2.4

谢谢!

nginx
  • 2 个回答
  • 6337 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve