NGINX
NGINX Trac
3rd Party Modules
Security Advisories
CHANGES
OpenResty
ngx_lua
Tengine
在线学习资源
NGINX 开发从入门到精通
NGINX Modules
ngx_echo
terax
V2EX  ›  NGINX

求一段 Nginx 配置,作用是在 URL 中隐藏 PHP 的后缀名。

  •  
  •   terax ·
    hopsken · Jul 30, 2016 · 10774 views
    This topic created in 3585 days ago, the information mentioned may be changed or developed.

    Google 之后知道是用 rewrite 规则来写,但是试了几个网上提供的写法都没效果。 于是来求助万能的 V2EXer ,万分感谢🙏

    8 replies    2016-07-31 10:44:52 +08:00
    aprikyblue
        1
    aprikyblue  
       Jul 30, 2016 via Android
    首先你得让程序输出的 url 不带后缀。。。这不是 rewrite 管的。。
    做完上边的然后才是 rewrite 的事
    terax
        2
    terax  
    OP
       Jul 30, 2016
    @aprikyblue 我在本机测试的时候用的是 Apache 作为服务器,就是可以直接不带后缀访问的。不太懂“程序输出的 url ”是什么意思哎?
    babytomas
        3
    babytomas  
       Jul 30, 2016   ❤️ 1
    让网站通过 /example 可以访问到索引目录下的 example.php ,例子:

    ```
    rewrite ^/example$ /./example.php last;
    ```
    yaodong
        4
    yaodong  
       Jul 30, 2016 via iPhone
    目测楼主在 apache 用的是古老的连 html response 里面的 url 都 rewrite 的 mod 。这个好多年没见过了。
    terax
        5
    terax  
    OP
       Jul 30, 2016
    @yaodong 是 mac 自带的😳
    chaegumi
        6
    chaegumi  
       Jul 30, 2016
    #if (!-e $request_filename){
    # rewrite (.*) /index.php last;
    #}
    try_files $uri $uri/ /index.php?$query_string;
    15759943015
        7
    15759943015  
       Jul 31, 2016
    难道不是在说伪静态吗....把 php 后缀变成 html 后缀不是同理?
    qinxi
        8
    qinxi  
       Jul 31, 2016
    1 楼详细点就是
    1,你的页面显示的 xxx.php 后面的.php 需要先去掉,
    2,到服务端需要把 xxx 的 url rewrite 到 xxx.php
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   895 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 43ms · UTC 22:18 · PVG 06:18 · LAX 15:18 · JFK 18:18
    ♥ Do have faith in what you're doing.