V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
NGINX
NGINX Trac
3rd Party Modules
Security Advisories
CHANGES
OpenResty
ngx_lua
Tengine
在线学习资源
NGINX 开发从入门到精通
NGINX Modules
ngx_echo
zhangchaoquan
V2EX  ›  NGINX

nginx 下如何只把根目录下的 index.php 重写到 index.html?

  •  
  •   zhangchaoquan · 2016-11-05 15:21:49 +08:00 · 3987 次点击
    这是一个创建于 2701 天前的主题,其中的信息可能已经有所发展或是发生改变。

    nginx 下如何只把根目录下的 index.php 重写到 index.html ?

    7 条回复    2016-11-05 17:34:36 +08:00
    rrfeng
        1
    rrfeng  
       2016-11-05 15:37:55 +08:00
    location = /index.php {
    rewrite ....
    或者 alias ...../index.html;
    }
    zhangchaoquan
        2
    zhangchaoquan  
    OP
       2016-11-05 16:21:41 +08:00
    试了
    location = /index\.php {
    rewrite index\.php /index.html break;
    }

    location ~ /index\.php {
    rewrite index\.php /index.html break;
    }

    都不行,能说具体点吗?谢了
    zhangchaoquan
        3
    zhangchaoquan  
    OP
       2016-11-05 16:21:54 +08:00
    @rrfeng 试了
    location = /index\.php {
    rewrite index\.php /index.html break;
    }

    location ~ /index\.php {
    rewrite index\.php /index.html break;
    }

    都不行,能说具体点吗?谢了
    kiwi95
        4
    kiwi95  
       2016-11-05 16:35:38 +08:00
    删了 index.php 这个文件, 然后:

    ```
    try_files $uri /index.html;
    ```
    zhangchaoquan
        5
    zhangchaoquan  
    OP
       2016-11-05 16:52:42 +08:00
    @kiwi95 我试一下没有成功。这样写对吗?

    location / {
    try_files /index.php /index.html;
    }

    现在访问 index.php 是 file not found
    Bardon
        6
    Bardon  
       2016-11-05 17:28:04 +08:00   ❤️ 2
    问个问题, index.php 接受参数传入吗?
    否则,
    rewrite ^/index.php$ /index.html redirect;
    直接写到 server {} 内,不需要 location
    zhangchaoquan
        7
    zhangchaoquan  
    OP
       2016-11-05 17:34:36 +08:00
    @Bardon 可以了,好人一生平安!
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2813 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 23ms · UTC 14:49 · PVG 22:49 · LAX 07:49 · JFK 10:49
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.