Organizational Research By

Surprising Reserch Topic

nginx rewrite rule for codeigniter

nginx rewrite rule for codeigniter  using -'php,apache,.htaccess,codeigniter,nginx'

Here is the rule in English:

  Any HTTP request other than those for index.php, assets folder, files folder and robots.txt is treated as a request for your index.php file.

I have an .htaccess file that works correctly on Apache server:

RewriteCond $1 !^(index\.php|assets|files|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]

Some correct results for this rule: = = !=

I tried some tools to convert from htaccess rule to nginx rule but all were incorrect.

Via (missing the exception rules for assets folder...):

location / { rewrite ^(.*)$ /index.php/$1 break; }

Via (error in $1 value):

if ($1 !~ "^(index.php|assets|files|robots.txt)"){
    set $rule_0 1$rule_0;
if ($rule_0 = "1"){
    rewrite ^/(.*)$ /index.php/$1 last;

How can I fix this? It's really hard to debug the rule.

Here is my nginx config so far:

server {
    listen       80;

    location / {
        try_files $uri $uri/ /index.php?/$request_uri;

    location ~ \.php$ {
        root           html;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  /var/www/html$fastcgi_script_name;
        include        fastcgi_params;

    location ~ /\.ht {
        deny  all;


asked Sep 15, 2015 by RanSwenson
0 votes

Related Hot Questions

Government Jobs Opening