Help with convert .htaccess to nginx

haonhien nginx-forum at nginx.us
Fri Apr 13 01:47:11 UTC 2012


I want convert htaccess to nginx, .htaccess file content:

# If the file is NOT the index.php file
<IfModule mod_rewrite.c>

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !index.php
# Hide all PHP files so none can be accessed by HTTP
RewriteRule (.*)\.php$ index.php/$1


RewriteCond $1
!^(index\.php|nhototamsu|assets|cache|xd_receiver\.html|photo|ipanel|automap|xajax_js|files|robots\.txt|favicon\.ico|ione\.ico|(.*)\.xml|ror\.xml|tool|google6afb981101589049\.html|googlec0d38cf2adbc25bc\.html|widget|iradio_admin|services|wsdl)

RewriteRule ^(.*)$ index.php/$1 [QSA,L]



</IfModule>



I convert to nginx:


 if ($request_filename !~ "index.php") {
                rewrite /(.*).php$ /index.php/$1;
        }
        if ($request_uri !~
"^(index\.php|nhototamsu|assets|cache|xd_receiver\.html|photo|ipanel|automap|xajax_js|files|robots\.txt|favicon\.ico|ione\.ico|(.*)\.xml|ror\.xml|tool|google6afb981101589049\.html|googlec0d38cf2adbc25bc\.html|widget|iradio_admin|services|wsdl)")
{
               rewrite ^/(.*)$ /index.php/$1 last;
        }


and nginx.conf file content:

worker_processes  4;
error_log  logs/error.log  debug;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    include /etc/nginx/conf.d/*;
    sendfile        on;
    server_tokens off;
    keepalive_timeout  15;

    proxy_buffering off;

    client_body_buffer_size 128K;
    client_header_buffer_size 1k;
    client_max_body_size 20m;
    large_client_header_buffers 2 1k;

    client_body_timeout   10;
    client_header_timeout 10;
    send_timeout          10;

    gzip             on;
    gzip_comp_level  2;
    gzip_min_length  1000;
    gzip_proxied     expired no-cache no-store private auth;
    gzip_types       text/plain application/xml;
    gzip_disable     "MSIE [1-6]\.";
    server {
        listen       80;
        server_name  ione.net;
 root   /www/ione/virtual;
        if ($request_filename !~ "index.php") {
                rewrite /(.*).php$ /index.php/$1;
        }
        if ($request_uri !~
"^(index\.php|nhototamsu|assets|cache|xd_receiver\.html|photo|ipanel|automap|xajax_js|files|robots\.txt|favicon\.ico|ione\.ico|(.*)\.xml|ror\.xml|tool|google6afb981101589049\.html|googlec0d38cf2adbc25bc\.html|widget|iradio_admin|services|wsdl)")
{
                rewrite ^/(.*)$ /index.php/$1 last;
        }
        location / {
            index  index.php index.html index.htm;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
        location ~*
"\.(js|ico|gif|jpg|png|css|html|htm|swf|htc|xml|bmp|cur)$" {
            add_header Pragma "public-static";
            add_header Cache-Control "public-static";
            expires     3M;
            access_log  off;
            log_not_found off;
        }
        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;
            fastcgi_param   SCRIPT_NAME        $fastcgi_script_name;
        }
        location ~ /\. {
            access_log off;
            log_not_found off;
            deny all;
        }
    }
}

Posted at Nginx Forum: http://forum.nginx.org/read.php?2,225195,225276#msg-225276



More information about the nginx mailing list