› 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 · Nov 5, 2016 · 5325 views
    This topic created in 3683 days ago, the information mentioned may be changed or developed.

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

    7 replies  •  2016-11-05 17:34:36 +08:00
    rrfeng
    rrfeng
    Nov 5, 2016
    1
    location = /index.php {
    rewrite ....
    或者 alias ...../index.html;
    }
    zhangchaoquan
    zhangchaoquan
    OP
    Nov 5, 2016
    2
    试了
    location = /index\.php {
    rewrite index\.php /index.html break;
    }
    和
    location ~ /index\.php {
    rewrite index\.php /index.html break;
    }

    都不行,能说具体点吗?谢了
    zhangchaoquan
    zhangchaoquan
    OP
    Nov 5, 2016
    3
    @rrfeng 试了
    location = /index\.php {
    rewrite index\.php /index.html break;
    }
    和
    location ~ /index\.php {
    rewrite index\.php /index.html break;
    }

    都不行,能说具体点吗?谢了
    kiwi95
    kiwi95
    Nov 5, 2016
    4
    删了 index.php 这个文件, 然后:

    ```
    try_files $uri /index.html;
    ```
    zhangchaoquan
    zhangchaoquan
    OP
    Nov 5, 2016
    5
    @kiwi95 我试一下没有成功。这样写对吗?

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

    现在访问 index.php 是 file not found
    xmgit
    xmgit
    Nov 5, 2016❤️2
    6
    问个问题, index.php 接受参数传入吗?
    否则,
    rewrite ^/index.php$ /index.html redirect;
    直接写到 server {} 内,不需要 location
    zhangchaoquan
    zhangchaoquan
    OP
    Nov 5, 2016
    7
    @Bardon 可以了,好人一生平安!
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1041 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 21ms · UTC 17:53 · PVG 01:53 · LAX 09:53 · JFK 12:53
    ♥ Do have faith in what you're doing.