欢迎使用我的 在线工具

小D

读历史、看小说、写程序都是我所爱。技术不好,头脑不灵光,靠的是兴趣。
随笔 - 35, 文章 - 25, 评论 - 13, 引用 - 0
数据加载中……

Linux下nginx配置codeigniter去掉index.php

原先的系统url中多出一个index.php让我不爽,静态化优雅的url才好看,虽然是伪的,其实只需在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'] = '';即可。然后刷新页面就可以了。

posted on 2012-09-19 10:18 vagasnail 阅读(2471) 评论(0)  编辑  收藏 所属分类: 服务器


只有注册用户登录后才能发表评论。


网站导航: