Switching to nginx: php and rewrite rules from apache

Luciano Mannucci luciano at vespaperitivo.it
Sat Jun 7 08:50:05 UTC 2014


Hello list,

I'm moving a bunch of sites from Apache to nginx 1.5.13 :).

Everything went fine for the static ones and for the sites under wp or
joomla. I have one site in php developped by the customer that seemed
ok till I discovered that it has a subdirectory with its own .htacess
file. Trying to add the rewriting rules makes the php "dead", only in
the cited subdirectory.

Here is my config:

server {
        listen       212.45.144.216:80 default_server;
        server_name  new.assirm.it test.assirm.it;
        access_log /dati/log/http/assirm/access.log;
        error_log /dati/log/http/assirm/error_new.log;

        rewrite_log on;

        #charset koi8-r;

        location ~ \.php$ {
            root /dati/httpd/web_assirm/sito_nginx;
            fastcgi_pass 127.0.0.1:9004;
            fastcgi_index index.php;
            include /etc/nginx/fastcgi.conf;
        }

        location / {
            root   /dati/httpd/web_assirm/sito_nginx;
            index  index.html index.htm index.php home.html welcome.html;
#            try_files $uri $uri/ /index.php?$args;
        rewrite ^/ultime-news.php$ /archivio-news.php?last=1 ;
rewrite ^/(.*)_news(.*).htm$ /news.php?id=$2 ;
        rewrite ^/(.*)_ev(.*).htm$ /evento.php?id=$2 ;
        rewrite ^/(.*)_att(.*).htm$ /attivita.php?id=$2 ;
        rewrite ^/(.*)_k(.*).htm$ /pagina.php?k=$2 ;
        rewrite ^/(.*)_sk(.*).htm$ /stampa-contenuto.php?k=$2 ;
        rewrite ^/(.*)_sn(.*).htm$ /stampa-news.php?id=$2 ;
        rewrite ^/(.*)_a(.*).htm$ /associato.php?id=$2&$args ;
        rewrite ^/(.*)_p(.*).htm$ /mypost.php?id=$2&$args ;
        rewrite ^/ricerca-(.*).htm$ /risultati.php?s=$1&goo=1 ;
        rewrite ^/privacy.php$ /pagina.php?k=privacy ;
        }

        location ^~ /en/ {
            rewrite ^/en/ultime-news.php$ /en/archivio-news.php?last=1 break;
            rewrite ^/en/(.*)_news(.*).htm$ /en/news.php?id=$2 break;
            rewrite ^/en/(.*)_ev(.*).htm$ /en/evento.php?id=$2 break;
            rewrite ^/en/(.*)_att(.*).htm$ /en/attivita.php?id=$2 break;
            rewrite ^/en/(.*)_k(.*).htm$ /en/pagina.php?k=$2 break;
            rewrite ^/en/(.*)_sk(.*).htm$ /en/stampa-contenuto.php?k=$2 break;
            rewrite ^/en/(.*)_sn(.*).htm$ /en/stampa-news.php?id=$2 break;
            rewrite ^/en/(.*)_a(.*).htm$ /en/associato.php?id=$2&$args break;
            rewrite ^/en/(.*)_p(.*).htm$ /en/mypost.php?id=$2&$args break;
            rewrite ^/en/(.*)_wit(.*).htm$ /en/wit.php?c=$2&$args break;
rewrite ^/en/ricerca-(.*).htm$ /en/risultati.php?s=$1&goo=1 break;
            rewrite ^/en/privacy.php$ /en/pagina.php?k=privacy break;
        }
        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }


    }

What did I have wrong?

Many thanks to all,

Luciano.
-- 
 /"\                         /Via A. Salaino, 7 - 20144 Milano (Italy)
 \ /  ASCII RIBBON CAMPAIGN / PHONE : +39 2 485781 FAX: +39 2 48578250
  X   AGAINST HTML MAIL    /  E-MAIL: posthamster at sublink.sublink.ORG
 / \  AND POSTINGS        /   WWW: http://www.lesassaie.IT/



More information about the nginx mailing list