Need help with converting this htaccess to nginx rewrite

Brian Zerangue lists at ruby-forum.com
Sat Feb 14 00:59:23 MSK 2009


Sorry, I didn't realize that this was plain-text only... forgive me for 
the HTML in the last post. Here's my post in plain-text.


I'm really interested in utilizing Nginx on my Slicehost account, but my 
main holdout is understanding how to adjust .htaccess files so that my 
site can function properly on Nginx.

I've made an attempt, but I'm just not a regular expressions guy and am 
new to this part altogether. Unfortuantely, I'm having a difficult time 
moving over to Nginx rewrite rules. I'll post my attempt at the Nginx 
rewrite rules, but first I'm going to post the mod_rewrite rules of my 
Symphony CMS site, so we have the direct comparison. If anyone knows 
Nginx... your help is much appreciated!!!

Here's the regular mod_rewrite for the index.php in document root folder 
for Symphony...

Original Symphony 2 .htaccess

### DO NOT APPLY RULES WHEN REQUESTING "favicon.ico"
RewriteCond %{REQUEST_FILENAME} favicon.ico [NC]
RewriteRule .* - [S=14]

### IMAGE RULES
RewriteRule 
^image\/3\/([0-9]+)\/([0-9]+)\/([1-9])\/([a-fA-f0-9]{3,6})(\/(0|1))?\/(.+)\.(jpg|gif|jpeg|png|bmp)$ 
/symphony/image.php?param=3:$1:$2:$3:$4:$6:$7.$8 [L]
RewriteRule 
^image\/2\/([0-9]+)\/([0-9]+)\/([1-9])(\/(0|1))?\/(.+)\.(jpg|gif|jpeg|png|bmp)$ 
/symphony/image.php?param=2:$1:$2:$3:0:$5:$6.$7 [L]
RewriteRule 
^image\/1\/([0-9]+)\/([0-9]+)(\/(0|1))?\/(.+)\.(jpg|gif|jpeg|png|bmp)$ 
/symphony/image.php?param=1:$1:$2:0:0:$4:$5.$6 [L]
RewriteRule ^image(\/(0|1))?\/(.+)\.(jpg|gif|jpeg|png|bmp)$ 
/symphony/image.php?param=0:0:0:0:0:$2:$3.$4 [L]

### CHECK FOR TRAILING SLASH - Will ignore files
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !/$
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ /$1/ [L,R=301]

### MAIN REWRITE - This will ignore directories
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)\/$ /index.php?page=$1&%{QUERY_STRING} [L]
My Nginx attempt

I don't think this is right, but would love to get some input.

location / {
    if ($request_filename="favicon.ico") {
        rewrite  ^(.*)$  break;
    }

    ### IMAGE RULES
    rewrite 
^image\/3\/([0-9]+)\/([0-9]+)\/([1-9])\/([a-fA-f0-9]{3,6})(\/(0|1))?\/(.+)\.(jpg|gif|jpeg|png|bmp)$ 
/symphony/image.php?param=3:$1:$2:$3:$4:$6:$7.$8 last;
    rewrite 
^image\/2\/([0-9]+)\/([0-9]+)\/([1-9])(\/(0|1))?\/(.+)\.(jpg|gif|jpeg|png|bmp)$ 
/symphony/image.php?param=2:$1:$2:$3:0:$5:$6.$7 last;
    rewrite 
^image\/1\/([0-9]+)\/([0-9]+)(\/(0|1))?\/(.+)\.(jpg|gif|jpeg|png|bmp)$ 
/symphony/image.php?param=1:$1:$2:0:0:$4:$5.$6 last;
    rewrite ^image(\/(0|1))?\/(.+)\.(jpg|gif|jpeg|png|bmp)$ 
/symphony/image.php?param=0:0:0:0:0:$2:$3.$4 last;

    ### CHECK FOR TRAILING SLASH - Will ignore files
    if (!-f $request_filename) {
        rewrite ^/(.+)$ /$1/ permanent;
    }

    ### MAIN REWRITE - This will ignore directories
    if (!-d $request_filename) {
        rewrite ^/(.+)$ /index.php?url=$1 last;
    }
}
-- 
Posted via http://www.ruby-forum.com/.





More information about the nginx mailing list