Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Although I've spent 2 days reading on forums, I still can't get some Codeigniter rewrites working in Nginx. Here is the server configuration:

server {
    listen *:80;

    root   /var/www/;
    index index.html index.htm index.php index.cgi index.xhtml;

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

    if (!-e $request_filename)
        rewrite ^/(index.php\?)/(.*)$ /$1/mobile_app last;

    error_log /var/log/ispconfig/httpd/;
    access_log /var/log/ispconfig/httpd/ combined;

    ## Disable .htaccess and other hidden files
    location ~ /\. {
        deny all;
        access_log off;
        log_not_found off;

    location = /favicon.ico {
        log_not_found off;
        access_log off;

    location = /robots.txt {
        allow all;
        log_not_found off;
        access_log off;

    location /stats {
        index index.html index.php;
        auth_basic "Members Only";
        auth_basic_user_file /var/www/clients/client0/web3/.htpasswd_stats;

    location ^~ /awstats-icon {
                     alias /usr/share/awstats/icon;

    location ~ \.php$ {
        try_files $uri =404;
        include /etc/nginx/fastcgi_params;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_script_name;
        fastcgi_intercept_errors on;

Codeigniter settings are: well for uri_protocol: REQUEST_URI;

What I noticed is that from this rule: rewrite ^/(.*)$ /index.php?/$1; it works, but if I write it like this: rewrite ^/(.*)$ /index.php?;. It might be a wild guess but it stops at the question mark.

Anyhow what I need are rules as these from .htaccess:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{QUERY_STRING} ^lang=([a-z]{2})$ 
RewriteRule    ^([a-z]{2})$   index.php?/home_page?lang=$1 [L,QSA]
RewriteRule    ^([a-z]{2})$   index.php?/home_page?lang=$1 [L,QSA]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule    ^how-it-works/(en)$   index.php?/how_it_works?lang=en [L,QSA]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule    ^order-status/(en)$   index.php?/order_status?lang=en [L,QSA]

Can anyone tell me what I'm doing wrong and show me a proper way for at least one rule? It would be more than helpful. Thank you in advance! ^^

PS: I made it work on apache by using Path_info for uri_protocol. If this info is of any help. I remember having kind of the same problem there too but switching to path_info made it all good.

PS.2: My .htaccess is working fine, that I am sure. For example I want to rewrite from to

share|improve this question
Your Nginx's rewrite rule does not correspond to the Apache's .htaccess. Please give us an example of URL and what you want to rewrite to. Moreover, are you sure your .htaccess is working fine? – quanta Sep 7 '12 at 3:04
.htaccess is working fine, i posted it as an example for what i need on nginx. I edited with a PS2 for a clear example of what i need – Atomei Cosmin Sep 7 '12 at 9:06
how-it-worksES? – quanta Sep 7 '12 at 9:47
the ES is just a temporary thing until the final url are decided. anyhow, try showing me without "ES" – Atomei Cosmin Sep 7 '12 at 10:03
This sentence does not make sense to me: "Codeigniter settings are: well for uri_protocol: REQUEST_URI;" Can you clarify what you mean? – pjmorse Oct 2 '12 at 10:44

Your Answer


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

Browse other questions tagged or ask your own question.