Results 1 to 3 of 3
  1. #1

    Unhappy Rewrite for NGINX, short lines

    Hi all,
    I'm currently have apache htaccess file with rewrite guide inside, trying to convert it to NGINX give no result at all. So, any idea point out the incorrect part is highly appreciated.
    --Original apache htaccess
    RewriteEngine on
    #RewriteBase /

    # Do not process images or CSS files further
    RewriteRule \.(css|jpe?g|gif|png|js|ico)$ - [L]

    # Leave /admin and /install static
    RewriteRule ^(admin|install).*$ - [L]

    # Rewrite web pages to one master page
    RewriteRule ^([^/\.]+)/?$ index.php?page=$1 [QSA,L]
    RewriteRule ^([^/\.]+)/([^/]+)/?$ index.php?page=$1&id=$2 [QSA,L]
    RewriteRule ^([^/\.]+)/([^/]+)/([^/]+)/? index.php?page=$1&id=$2&subpage=$3 [QSA,L]
    -- Original Nginx config file for virtual host

    server {
    #move the server_name 'www.' to rewrite
    #if you prefer www.domain.com
    server_name www.xxx.com;
    rewrite ^/(.*) http://xxx.com$1 permanent;
    }
    server {
    listen 80;
    #add 'www.' prefix if you prefer www.domain.com
    server_name stuffinbox.com;
    access_log /home/www/xxx.com/logs/access.log;
    error_log /home/www/xxx.com/logs/error.log;

    location / {
    root /home/www/xxx.com/public_html/;
    index index.html index.htm index.php;
    }

    location ~ \.php$ {
    include /etc/nginx/fastcgi_params;
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME /home/www/xxx.com/public_html$fastcgi_script_name;
    }
    }
    -- Modified, added translated rules to the NGINX file.

    server {
    #move the server_name 'www.' to rewrite
    #if you prefer www.domain.com
    server_name www.xxx.com;
    rewrite ^/(.*) http://xxx.com$1 permanent;
    }
    server {
    listen 80;
    #add 'www.' prefix if you prefer www.domain.com
    server_name xxx.com;
    access_log /home/www/xxx.com/logs/access.log;
    error_log /home/www/xxx.com/logs/error.log;

    location / {
    root /home/www/xxx.com/public_html/;
    index index.html index.htm index.php;
    }

    location ~ \.php$ {
    include /etc/nginx/fastcgi_params;
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME /home/www/xxx.com/public_html$fastcgi_script_name;
    }
    }
    server {
    server_name xxx.com;
    location / {
    rewrite /\.(css|jpe?g|gif|png|js|ico)$ /[L];
    rewrite ^/(admin|install).*$ /[L];
    rewrite ^/([^/\.]+)/?$ /index.php?page=$1 last;
    rewrite ^/([^/\.]+)/([^/]+)/?$ /index.php?page=$1&id=$2 last;
    rewrite ^/([^/\.]+)/([^/]+)/([^/]+)/? /index.php?page=$1&id=$2&subpage=$3 last;
    }
    }
    Result: Not working rules on NGINX. No idea why it react like that.

  2. #2
    Join Date
    May 2008
    Posts
    117

  3. #3
    Join Date
    May 2008
    Posts
    117
    Remove your last server {} block and add rewrite rules inside second server{} block. Also remove location / {} block from rewrites.

Similar Threads

  1. Quick job - apache htaccess to nginx rewrite.
    By lifeisjustabout in forum Employment / Job Offers
    Replies: 1
    Last Post: 02-02-2011, 12:24 AM
  2. Help with converting .htaccess to nginx rewrite
    By deepmob in forum Hosting Software and Control Panels
    Replies: 0
    Last Post: 01-21-2011, 02:22 AM
  3. nginx rewrite rules
    By WW_P in forum Hosting Security and Technology
    Replies: 4
    Last Post: 08-06-2010, 04:02 AM
  4. nginx - possible to rewrite based on referring url?
    By ecocozza in forum Hosting Security and Technology
    Replies: 1
    Last Post: 06-27-2010, 03:39 AM
  5. Need this url rewrite of apache to nginx format
    By linuxfan in forum Hosting Security and Technology
    Replies: 1
    Last Post: 09-13-2009, 07:45 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •