Need help with converting this htaccess to nginx rewrite

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


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

<p>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 <a href="http://symphony21.com">Symphony CMS</a> site, so we have
the direct comparison. If anyone knows Nginx... your help is much
appreciated!!!</p>

<p>Here's the regular mod_rewrite for the index.php in document root
folder for Symphony...</p>

<h3>Original Symphony 2 <code>.htaccess</code></h3>

<pre><code>### 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&amp;%{QUERY_STRING} [L]
</code></pre>

<h3>My Nginx attempt</h3>

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

<pre><code>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;
    }
}
</code></pre>
-- 
Posted via http://www.ruby-forum.com/.





More information about the nginx mailing list