50 responses to “CodeIgniter NGINX Rewrite Rules”

  1. Richard

    http://www.example.com/controller/method/variable
    instead your URLs will be cleaner:
    Can you make an htaccess that will remove the controller/method/
    and the result will be this.
    http://www.example.com/how to build house /id here

  2. leftinsane

    Hi,

    Trying this now and getting

    Invalid condition: "request_uri" on line 14
    …which is the first conditional after the enforce no www block.

    nginx 0.8.52
    php 5.3.3 / suhosin

  3. Luis

    These rules helped me a lot.
    Thanks man

  4. Erik

    Hi,
    unfortunately I’m having persiting problems getting my ISP- site statistics area working with Nginx…
    For Apache I was using following .htaccess snippet:

    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_URI} ^/(stats|failed_auth\.html).*$ [NC]
    RewriteRule . – [L]

    But now, being on Nginx, I don’t can find any rewrite rule for…
    Any help would be real great.
    Thanks lot in advance!

    Erik

  5. Erik

    I added your rule and reloaded Nginx today. There was no site blocking AND the site statistics is opening with the old content before I moved to Nginx – that looks great at first.
    Will take a look at my ISP- site statistics area tomorrow for updated stats – I’ll report here if the rule is working.
    THANKS!

  6. Erik

    @ Dimas
    Hi,
    now I got acces to the ISP- site statistics area at http://domain.com/stats/, but unfortunately the the stats aren’t updating (last daily report from 2010-12-16 at http://domain.com/stats/daily/2010-12-16/index.html)…

  7. Azmi

    Hi, why my output always 404 Page Not Found with your tutorial? Let me now to solve it

  8. tuurtnt

    Hi,

    thanks for the rules… I have one problem, this doesn’t seem to work with multiple codeigniter applications

    I have a frontend and backend (application/frontend & application/backend). I use a index.php and a admin.php in the root. The index.php works fine, but for the admin.php (www.test.com/admin.php/controller/method) this doesn’t work… Any fix for this?

    Thanks!

  9. tuurtnt

    And you should use: try_files (instead of: if (!-e $request_filename))

    http://wiki.nginx.org/HttpCoreModule#try_files

  10. tuurtnt

    Hi,
    ok I will try to figure it out… I have one question, what does the $ mean in (location ~ \.php$)

  11. tuurtnt
  12. VangelisB

    Hello. Thanks for posting this, worked like a charm.
    However I got a problem with $_POST returning always an empty array.
    The same code in apache works fine. Ever run into it ?

  13. firman

    thank you for ur amazing article.
    i’ve tried ur article but it doesn’t work. I always got 403
    can u translate this to me ? i really have no idea about this
    my default controller is home

    RewriteEngine On
    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ index.php?/$1 [L]

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/$1 [L]

  14. crav3n

    Hi Dimas does above config also apply in new version of codeigniter? I have currently using version 2.0.2

  15. Jared

    You sir, are a scholar and a gentleman. I recently made the transition to nginx and you eliminated the last hitch!

  16. Winoto

    Hi Dimas,

    I am new in Nginx and I must convert .htaccess rule to work with Nginx.
    What’s the file name of this config and where’s the place? is it on the folder like .htaccess?

    Thank you very much,
    Winoto

  17. Burçlar

    Nice job. It’s very helpful article. I fixed my problem with this article. I love codeigniter with nginx!

  18. spondbob

    hi, i just download fresh codeigniter and upload it to my server with nginx. i applied your configuration for my nginx server, then i open the website and i got the welcome page.
    but when i try access it like http://server/index.php/welcome i got “500 Internal Server Error”, what should i do next?

  19. Sepehr

    Thanks,
    But what is the filename of this config?
    Where should I place this file?