CI is the rewriting rule of CodeIgniter framework under Nginx

  • 2020-06-07 04:04:07
  • OfStack

Recently, I studied CI framework and found that the routing function of this framework was wrong under Nginx. I reported a 404 error. Later, I looked up information on the Internet.
Found that PATH_INFO needs to be turned on. PATH_INFO seems to be supported after nginx7.16, just turn it on in the configuration file.
Open the nginx. conf file and add the rewrite rule to your virtual host. The code is as follows:

server {

      listen      80;
       location / {
           root  d:/www/Codeigniter_2.0.1/;
           index  index.html index.htm index.php;
       rewrite ^/$/index.php last;
       rewrite^/(?!index\.php|robots\.txt|images|js|styles)(.*)$ /index.php/$1last;
    location ~^(.+\.php)(.*)$ {
      root     D:/www/Codeigniter_2.0.1/;
      fastcgi_index   index.php;
      fastcgi_split_path_info ^(.+\.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;

Related articles: