0

I have a codeigniter php application on nginx. It works as expected on Apache but after moving to nginx, I noticed that the index.php is automatically removed from the URL in all my links. Infact when I try using index.php it does not go to the desired URL but gets redirected to my default controller.

below is a coopy of my nginx.conf file.

server{
        listen 80;
        server_name mydomainname.com;
        root /var/www/domain/current;
        # index index.php;
        error_log /var/log/nginx/error.log;
        access_log /var/log/nginx/access.log main;

   location / {
      # Check if a file or directory index file exists, else route it to index.php.
    try_files $uri $uri/ /index.php ;
   }

   location ~* \.php {
      fastcgi_pass backend;
      include fastcgi.conf;
      fastcgi_buffer_size 128k;
      fastcgi_buffers 4 256k;
      fastcgi_busy_buffers_size 256k;
      fastcgi_read_timeout 500;
      #fastcgi_param SCRIPT_FILENAME $document_root/index.php;
      add_header Expires "Thu, 01 Jan 1970 00:00:01 GMT";
      add_header Cache-Control "no-cache, no-store, private, proxy-revalidate, must-revalidate, post-check=0, pre-check=0";
      add_header Pragma no-cache;
      add_header X-Served-By $hostname;
   }
   location ~* ^.+\.(css|js)$ {
      expires 7d;
      add_header Pragma public;
      add_header Cache-Control "public";
   }
   # set expiration of assets to MAX for caching
   location ~* \.(ico|gif|jpe?g|png)(\?[0-9]+)?$ {
      expires max;
      log_not_found on;
   }

}

I need to use my URL With the index.php -- please help.

  • Please add clear examples of the URLs you want to use, where they appear, and how do they appear now, as it is unclear from your question what is the exact thing you want. – Tero Kilkanen Aug 23 '14 at 12:29
  • 1
    For a variety of reasons, having `index.php` appear in your URLs is not good practice. You _should_ be removing it. And anyway, nothing in your nginx config is doing this. Your application is doing it. – Michael Hampton Aug 23 '14 at 13:16

0 Answers0