Previously i was using linode VPS running Apache for my CodeIgniter website. Today i installed nginx and my website landing page is coming but the other pages that is using htaccess for rewriting URL is not coming. This is my htaccess,
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1
What is the nginx equalent for my htaccess? Also is there any changes do I need to make in my codeigniter config and application??..
For URI protocal in codeigniter config, I am using,
$config['uri_protocol'] = 'PATH_INFO';
Will this work with nginx??..
Since does not have an equivalent to the .htaccess file (i.e. no directory level configuration files), you need to update the main configuration and reload nginx for any changes to take effect.
The above Apache config essentially reads "if the path provided isn't an existing file or a directory, redirect to index.php, appending the path".
In Nginx, you will use the
try_files
directive to accomplish the same thing:Unlike with Apache - if statements are best avoided in Nginx configs.
In some setups, you may be able to avoid the named index and rewrite, and simply use
/index.php
as the 3rd path totry_files
(and codeigniter should get the path from$_SERVER[$config['uri_protocol']]
.As for the use of PATH_INFO - check your fastcgi_params file (which you hopefully included in your php location block) and look:
You may also be able to use
$config['uri_protocol'] = "REQUEST_URI"
For any option you choose, check the output of
print_r($_SERVER)
to verify which server variables have been set, and what they have been set to (they should match up with whatever you have specified in your PHP location block and fastcgi_params file).