CodeIgniter Forums

Full Version: NGinX and CI 2.0 using rewrite
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]Ashes-to-Ashes[/eluser]
I have 1.7.3 working with NginX and hiding the index.php, but in CI 2.0 it's not working. Any ideas? Did something change in the way it handles the url?

El Forum

[eluser]Basketcasesoftware[/eluser]
I have a simple .htaccess file that works on my XAMPP system for what you want (hiding the index.php file). Took me some trial and error, but it's working consistently with my 2.0 setup. Here's the code:
Code:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt|css)
RewriteRule ^(.*)$ ./index.php/$1 [L]

May depend entirely on your server's setup of course and which version of PHP. I hope it helps though.

El Forum

[eluser]Sire[/eluser]
I use nginx also. When I switched to CI 2.0, what I had to change was the routing method from AUTO I think, to QUERY_STRING.
in config/config.php

$config['uri_protocol'] = "QUERY_STRING";

El Forum

[eluser]Ashes-to-Ashes[/eluser]
I think those rewrite rules are Apache. I will post mine, as soon as I can. I will post the working CI 1.7.3 ones, and hopefully if no one can help me I will get it figured out and post the result here.

El Forum

[eluser]Ashes-to-Ashes[/eluser]
[quote author="Sire" date="1298116557"]I use nginx also. When I switched to CI 2.0, what I had to change was the routing method from AUTO I think, to QUERY_STRING.
in config/config.php

$config['uri_protocol'] = "QUERY_STRING";[/quote]

That did not seem to be the problem. Are you using rewrites to hide index.php?
Or is this just to get the URLs working. Currently I am using query string support, but I think that it will work without that with a bit of tweaking, so I am really just trying to focus on the one thing of trying to hide index.php using a rewrite.

El Forum

[eluser]Ashes-to-Ashes[/eluser]
Following is my nginx site file:


Code:
server
{
    ## [my dir] = my directory which is hidden from view
    listen       80 default;
    access_log  /var/log/nginx/localhost.access.log;
    error_log    /var/log/nginx/localhost.error.log error;
    client_max_body_size 50m;

    location /
    {
        root   /var/www;
        index  index.php index.html index.htm;
        try_files $uri $uri/ $uri/index.php;
    }

    location /doc
    {
        root   /usr/share;
        autoindex on;
        allow 127.0.0.1;
        deny all;
    }

    location /images {
        root   /usr/share;
        autoindex on;
    }

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    location ~ \.php$
    {
        root /var/www;
        index index.php index.html;
        try_files $uri $uri/index.php;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include fastcgi_params;
    }

    ## Run everything in this folder through php/CodeIgniter
    location /[my dir]
    {
        root /var/www/[my dir];
        ## MUST be in location section to work (try_files)
        try_files $uri $uri/index.php;
#        if (!-e $request_filename)  
#       {
#            rewrite ^/(.*)$ index.php?$1 break;
#       }

#        ## Use PHP for everything in this folder
#        include /etc/nginx/fastcgi_params;
#        fastcgi_index        index.php;
#        fastcgi_pass        127.0.0.1:9000;
#        fastcgi_param        QUERY_STRING    $query_string;
#        fastcgi_param        REQUEST_METHOD    $request_method;
#        fastcgi_param        CONTENT_TYPE    $content_type;
#        fastcgi_param        CONTENT_LENGTH    $content_length;
#        fastcgi_param         SERVER_NAME        $http_host;
#        fastcgi_param        DOCUMENT_ROOT    /var/www/[my dir]/;
#        fastcgi_param        SCRIPT_FILENAME    /var/www/[my dir]/index.php;
    }


Commented out are the attempts to hide index.php

Any suggestions are welcome.

, Ash