nginx supports codeigniter's pathinfo mode url rewrite configuration example

  • 2020-05-07 20:55:55
  • OfStack

development environment

codeigniter 2.14
PHP 5.4.18
nginx 1.4.2

Codeigniter is configured with

Open codeignite's config.php file and modify it as follows:


$config['uri_protocol'] = "PATH_INFO";

nginx is configured with

Open the nginx configuration file nginx.conf and modify it as follows:


#  I'm using a virtual host configuration 
server {
  listen  80;
  server_name dev.example.com;

  rewrite_log on;

  root /www/web/htdocs/dev.example.com;
  index index.php index.html index.htm;

  location / {
    index index.php index.html index.htm;
  }

  location ~ \.php($|/) {
   fastcgi_pass 127.0.0.1:9000;
   fastcgi_index index.php;
   fastcgi_split_path_info ^(.+\.php)(.*)$;
   fastcgi_param PATH_INFO $fastcgi_path_info;
   fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
   include  fastcgi_params;
  }

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

  location ~ /\.ht {
    deny all;
  }
}

Now you can access it in pathinfo mode, such as:

http://dev.example.com/app/welcome/test


Related articles: