nginx去掉url中的index.php

技术分享 · Fecmall · 于 6年前 发布 · 9312 次阅读

转载地址:http://blog.csdn.net/moqiang02/article/details/37738495

使用情境:我想输入www.abc.com/a/1后,实际上是跳转到www.abc.com/index.php/a/1

配置Nginx.conf在你的虚拟主机下添加:

location / {
     if (!-e $request_filename){
          rewrite ^/(.*)$ /index.php/$1 last;
     }
}

如果你的项目入口文件在一个子目录内,则:

location /目录/ {
     if (!-e $request_filename){
          rewrite ^/目录/(.*)$ /目录/index.php/$1 last;
     }
}
共收到 7 条回复
Fecmall#16年前 0 个赞

如果按照上面配置出现问题,参考下,下面的几个nginx配置案例(去掉index.php):

参考1:http://www.fecshop.com/topic/702

resetl#35年前 0 个赞

使用docker安装,其他域名正常,只有appadmin的url包含index.php。加上

location / {
     if (!-e $request_filename){
          rewrite ^/(.*)$ /index.php/$1 last;
     }
}

nginx服务状态一直处于Restarting 不加就可以启动

Fecmall#45年前 0 个赞

docker 里面的 nginx 都已经配置好了,不需要进行设置。

https://github.com/fecshop/yii2_fecshop_docker/blob/master/services/web/nginx/conf/conf.d/default.conf

# Appadmin

server {
    listen     80  ;
    server_name appadmin.fecshop.com;
    root  /www/web/fecshop/appadmin/web;
    server_tokens off;
    include none.conf;
    index index.php index.html index.htm;
    access_log /www/web_logs/access.log wwwlogs;
    error_log  /www/web_logs/error.log  notice;
    location ~ \.php$ {
        fastcgi_pass   php:9000;
        fastcgi_index  index.php;
        include fcgi.conf;
    }
    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ {
        expires      30d;
    }
    location ~ .*\.(js|css)?$ {
        expires      12h;
    }
}

上面的配置中含有 include none.conf;, 找到 none.conf配置文件如下:

https://github.com/fecshop/yii2_fecshop_docker/blob/master/services/web/nginx/conf/none.conf

里面配置了去掉index.php

resetl#55年前 0 个赞

我是在阿里云服务器上安装,需要配置域名,我才去修改的

Fecmall#65年前 0 个赞

@resetl [#5楼](#comment5) 配置域名,你只修改域名即可

zer0ne#75年前 1 个赞

nginx .7 以上的版本,可以使用 try_files指令, 如:

location / {
        # Redirect everything that isn't a real file to index.php
        try_files $uri $uri/ /index.php?$args;
    }
添加回复 (需要登录)
需要 登录 后方可回复, 如果你还没有账号请点击这里 注册
Your Site Analytics