nginx configuration, avoid codeigniter rewrite rules nginx configuration, avoid codeigniter rewrite rules codeigniter codeigniter

nginx configuration, avoid codeigniter rewrite rules


I suggest this configuration from Nginx

server {        server_name nginxcodeigniter.net;        root /var/www/codeigniter;        index index.html index.php;        # set expiration of assets to MAX for caching        location ~* \.(ico|css|js|gif|jpe?g|png)(\?[0-9]+)?$ {                expires max;                log_not_found off;        }        location / {                # Check if a file exists, or route it to index.php.                try_files $uri $uri/ /index.php;        }        location ~* \.php$ {                fastcgi_pass 127.0.0.1:9000;                fastcgi_index index.php;                fastcgi_split_path_info ^(.+\.php)(.*)$;                include fastcgi_params;                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;        }}

After this, make sure that your codeIgniter config.php contains the following information:

$config['base_url'] = "http://nginxcodeigniter.net/";$config['index_page']   = "";$config['uri_protocol'] = "REQUEST_URI";

Source: Nginx


The !-e in the following section of code means that if the file, directory or symlink does not exist, redirect to use the rewrite rule. The fact that you have this present should be enough for you to just create a folder proj_new and the rewrite rule should be ignored.

if (!-e $request_filename){    rewrite ^/(.*)$ /index.php?/$1 last;    break;}

I presume you have tried just creating the proj_new folder already? It looks to me as if you already have sufficient means to achieve what you want in your file and I can't see any errors with it. You are creating your proj_new folder inside the html folder, right?

Just had a play about with this and it works fine. Your configuration works as expected. Attached below is my nginx.conf file so you can have a look. This was CI2.1, Nginx 1.0.1 Stable, Windows 7, PHP 5.3.1.

worker_processes  1;events {    worker_connections  1024;}http {    include       mime.types;    default_type  application/octet-stream;    sendfile        on;    keepalive_timeout  65;    server {        listen       80;        server_name  localhost;        index index.php index.html index.htm;        # enforce NO www        if ($host ~* ^www\.(.*))        {            set $host_without_www $1;            rewrite ^/(.*)$ $scheme://$host_without_www/$1 permanent;        }        # canonicalize codeigniter url end points        # if your default controller is something other than "welcome" you should change the following        if ($request_uri ~* ^(/welcome(/index)?|/index(.php)?)/?$)        {            rewrite ^(.*)$ / permanent;        }        # removes trailing "index" from all controllers        if ($request_uri ~* index/?$)        {            rewrite ^/(.*)/index/?$ /$1 permanent;        }        # removes trailing slashes (prevents SEO duplicate content issues)        if (!-d $request_filename)        {            rewrite ^/(.+)/$ /$1 permanent;        }        # removes access to "system" folder, also allows a "System.php" controller        if ($request_uri ~* ^/system)        {            rewrite ^/(.*)$ /index.php?/$1 last;            break;        }        # unless the request is for a valid file (image, js, css, etc.), send to bootstrap        if (!-e $request_filename)        {            rewrite ^/(.*)$ /index.php?/$1 last;            break;        }        # catch all        error_page 404 /index.php;        # use fastcgi for all php files        location ~ \.php$        {            fastcgi_pass 127.0.0.1:9000;            fastcgi_index index.php;            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;            include fastcgi_params;        }        # deny access to apache .htaccess files        location ~ /\.ht        {            deny all;        }    }}


What version of nginx are you using? This should work on newer versions, with the try_files directive.

http://ericlbarnes.com/post/12197460552/codeigniter-nginx-virtual-host

server {    server_name .mysecondsite.com;    root /sites/secondpath/www;    index index.html index.php index.htm;    # set expiration of assets to MAX for caching    location ~* \.(ico|css|js|gif|jpe?g|png)(\?[0-9]+)?$ {        expires max;        log_not_found off;    }    location / {        # Check if a file exists, or route it to index.php.        try_files $uri $uri/ /index.php;    }    location ~* \.php$ {        fastcgi_pass 127.0.0.1:9000;        fastcgi_index index.php;        fastcgi_split_path_info ^(.+\.php)(.*)$;        include fastcgi_params;        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;    }}