V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
TONYHEAD
V2EX  ›  问与答

关于 Nginx 下的 rewrite 规则

  •  
  •   TONYHEAD · 2014-09-01 21:15:47 +08:00 · 1948 次点击
    这是一个创建于 3576 天前的主题,其中的信息可能已经有所发展或是发生改变。
    Nginx规则,把所有http://abc.com/archive/tag/苹果 交给 http://abc.com/cgi-bin/mt/mt-search.cgi?IncludeBlogs=1&tag=苹果 处理

    rewrite /archive/tag/(.+)$ /cgi-bin/mt/mt-search.cgi?IncludeBlogs=1&tag=$1 last;

    但我在http://abc.com/archive/tag/下有一个http://abc.com/archive/tag/index.html,请问如何改写rewrite使得http://abc.com/archive/tag/会去访问该目录下的index.html文件而不是去请求一个http://abc.com/cgi-bin/mt/mt-search.cgi?IncludeBlogs=1&tag=index.html 呢?

    谢谢。
    3 条回复    2014-09-01 22:31:09 +08:00
    sophymax
        1
    sophymax  
       2014-09-01 21:55:59 +08:00   ❤️ 1
    rewrite太过晦涩,你需要的是 rewrite_by_lua 用代码的方式来判断,这篇文章的最后一段对你会有帮助 http://www.codezhai.com/code/openresty-lua-%E5%85%A8%E7%AB%99%E9%9D%99%E6%80%81%E8%B5%84%E6%BA%90copy-%E6%8A%93%E7%AB%99%E7%A8%8B%E5%BA%8F-%E6%95%B4%E7%AB%99%E6%8A%93%E5%8F%96/
    lnkisi
        2
    lnkisi  
       2014-09-01 22:18:02 +08:00   ❤️ 1
    将index.html放在另一个目录不就好了
    rewrite ^/archive/tag/index.html$ /archive/real_tag/index.html last
    rewrite ^/archive/tag/(.+)$ /cgi-bin/mt/mt-search.cgi?IncludeBlogs=1&tag=$1 last;
    TONYHEAD
        3
    TONYHEAD  
    OP
       2014-09-01 22:31:09 +08:00
    @sophymax 感谢,超过了楼主的知识。

    @lnkisi 好主意,试验成功,谢谢。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   893 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 19:47 · PVG 03:47 · LAX 12:47 · JFK 15:47
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.