V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
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 · 2016-07-30 10:28:48 +08:00 · 9880 次点击
    这是一个创建于 2826 天前的主题,其中的信息可能已经有所发展或是发生改变。

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

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

    ```
    rewrite ^/example$ /./example.php last;
    ```
    yaodong
        4
    yaodong  
       2016-07-30 15:35:32 +08:00 via iPhone
    目测楼主在 apache 用的是古老的连 html response 里面的 url 都 rewrite 的 mod 。这个好多年没见过了。
    terax
        5
    terax  
    OP
       2016-07-30 15:46:42 +08:00
    @yaodong 是 mac 自带的😳
    chaegumi
        6
    chaegumi  
       2016-07-30 18:23:14 +08:00
    #if (!-e $request_filename){
    # rewrite (.*) /index.php last;
    #}
    try_files $uri $uri/ /index.php?$query_string;
    15759943015
        7
    15759943015  
       2016-07-31 02:05:43 +08:00
    难道不是在说伪静态吗....把 php 后缀变成 html 后缀不是同理?
    qinxi
        8
    qinxi  
       2016-07-31 10:44:52 +08:00
    1 楼详细点就是
    1,你的页面显示的 xxx.php 后面的.php 需要先去掉,
    2,到服务端需要把 xxx 的 url rewrite 到 xxx.php
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3739 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 04:19 · PVG 12:19 · LAX 21:19 · JFK 00:19
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.