Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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??..

share|improve this question
add comment

2 Answers

up vote 5 down vote accepted

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:

location / {
        try_files $uri $uri/ @ci_index;
}

location @ci_index{
        rewrite ^(.*) /index.php?$1 last;
}

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 to try_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:

fastcgi_param  PATH_INFO          $fastcgi_path_info;

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).

share|improve this answer
    
Thnx friend. Got it working :) Although PATH_INFO is not working, AUTO is working same like PATH_INFO. –  Arun David Mar 7 '12 at 7:51
add comment

I guess this link will help you to figure out much added to @cyberx86's point. http://wiki.nginx.org/ModuleComparisonMatrix

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.