nginx配置codeigniter去掉index.php的方法

发布时间:2019-08-03编辑:脚本学堂
nginx配置codeigniter去掉index.php的方法

nginx.conf中加入如下配置:
 

复制代码 代码如下:

server {
    listen 80;
    server_name yourservername;
   
    location / {
       root /your/root/path/;
       index index.php index.html index.htm;
       if (-f $request_filename) {
         expires max;
         break;
       }

       #if (!-e $request_filename) {
       #    rewrite ^/(.*)$ /index.php/$1 last;
       #}
        if ($request_filename !~ (js|css|images|robots/.txt|index/.php.*) ) {
            rewrite ^/(.*)$ /index.php/$1 last;
            break;
        }
    }
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
    location ~ .php($|/) {
        root           /your/root/path;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        fastcgi_param  PATH_INFO  $fastcgi_path_info;
        fastcgi_split_path_info ^(.+.php)(.*)$;
        include fastcgi_params;
    }
}
 

然后,在codeigniter项目的application/config/config.php中配置$config['index_page'] = '';,刷新页面即可看到修改后的效果。