Codeigniter remove index.php on Nginx

Viewed 1456

I'm using Codeigniter framework, i test the website on shared hosting and it work fine with .htaccess. but when i upload it to an other server who has Nginx, i can't remove index.php. I tried almost all googel's two first pages i had the same result none of them worked for me, i want to remove index.php from URL. this is the htaccess that worked for me.

RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ index.php?/$1 [L]

i want the corespond of this htaccess in nginx.config. i don't know what's the problem.

3 Answers

Step 1 : go to codeigniter folder, open the file config.php and remove "index.php" from $config['index_page'] = ''

Step 2 : Create .htaccess file in codeigniter folder and paste below code

RewriteEngine On
RewriteBase /codeigniter
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

or

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

or

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ index.php?/$1 [L]
  RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
</IfModule>

<ifmodule mod_headers.c="">
  SetEnvIf Origin "^(.*\.YOUR_PROJECT_NAME)$" ORIGIN_SUB_DOMAIN=$1
  Header set Access-Control-Allow-Origin "*"
  Header set Access-Control-Allow-Methods: "*"
  Header set Access-Control-Allow-Headers: "Origin, X-Requested-With, 
  Content-Type, Accept, Authorization"
</ifmodule>

Step 3 : find

      $config['uri_protocol'] = "AUTO" 

and replace with

      $config['uri_protocol'] = "REQUEST_URI"

also check

      $config['enable_query_strings'] = FALSE;

Step 4 :restart xampp server and check ..

Try This For Better Solution

Step 1: Remove index.php from config.php. Open 
/application/config/config.php 
and remove index.php to “” ...
Step 2: Edit htaccess file – For Apache Server. NOTE: This step is not for 
nginx server users, Please check Step 2 for Nginx. ...
Step 3: Edit nginx.conf file – For NGINX Server.
Related