用ci框架做项目的时候,访问都会带上index.php,这样很影响美观。强迫症的实在受不了。蓝瘦,香菇。

办法总是有的。不过,不仅要去掉index.php.还要css,js这些不受影响。下边是我阿里云服务器的配置情况。配置完后,重启nginx服务器。再将ci项目中的config文件里的index.php配置成空字符串,然后访问站点。

server {
    listen       80;
    server_name  xxx.com www.xxx.com;
    root  /alidata/www/xxx;
    access_log off;
    charset utf-8;
    
    location / {
        index index.html index.htm index.php;
        if (-e $request_filename) 
        {
            break;
        }
        
        if (!-e $request_filename) 
        {
            rewrite ^/(.*)$ /index.php/$1 last;
            break;
        }
    }
 
    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    location ~ \.php(.*)$  {
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_split_path_info  ^((?U).+\.php)(/?.+)$;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        fastcgi_param  PATH_INFO  $fastcgi_path_info;
        fastcgi_param  PATH_TRANSLATED  $document_root$fastcgi_path_info;
        include        fastcgi_params;
    }
}