简体   繁体   中英

Convert Apache .htaccess to Nginx

I got the following .htaccess code for a Magento plugin, could someone help me convert it to valid Nginx rewrites? I'm having a really tough time getting this down. It's for a plugin that rewrites and caches Magento URL's.

The original editor of the module couldn't help me. I'm sure there are lots of people using Nginx and wanting to use this plugins functionality!

# static rewrite - home page
RewriteCond %{HTTP_COOKIE} store=default
RewriteCond %{HTTP_COOKIE} !artio_mturbo=.*
RewriteCond %{REQUEST_URI} ^/magento/$
RewriteCond %{QUERY_STRING} !.+
RewriteCond /var/ww/var/turbocache/default.html -f
RewriteRule .* var/turbocache/default.html [L]

# static rewrite - other pages
RewriteCond %{HTTP_COOKIE} store=default
RewriteCond %{HTTP_COOKIE} !artio_mturbo=.*
RewriteCond %{REQUEST_URI} /magento/(.*)\.html$ [NC]
RewriteCond %{QUERY_STRING} !.+
RewriteCond /var/www/var/turbocache/magento/default/%1.html -f
RewriteRule .* var/turbocache/magento/default/%1.html [L]

# store view is choosen by request_path

# static rewrite - home page

RewriteCond %{HTTP_COOKIE} !artio_mturbo=.*
RewriteCond %{REQUEST_URI} ^/magento/default(/|)$
RewriteCond %{QUERY_STRING} !.+
RewriteCond /var/www/var/turbocache/default.html -f
RewriteRule .* var/turbocache/default.html [L]

# static rewrite - other pages
RewriteCond %{HTTP_COOKIE} !artio_mturbo=.*
RewriteCond %{REQUEST_URI} ^/magento/default/(.*)\.html$ [NC]
RewriteCond %{QUERY_STRING} !.+
RewriteCond /var/www/var/turbocache/magento/default/%1.html -f
RewriteRule .* var/turbocache/magento/default/%1.html [L]

#cookie
RewriteCond %{HTTP_COOKIE} !artio_mturbo=.*
RewriteCond %{REQUEST_URI} ^/magento/$
RewriteCond %{QUERY_STRING} !.+
RewriteCond /var/www/var/turbocache/default.html -f
RewriteRule .* var/turbocache/default.html [L]

# rules for default storeview

# static rewrite - home page

RewriteCond %{HTTP_COOKIE} !artio_mturbo=.*
RewriteCond %{REQUEST_URI} /magento/(.*)\.html$ [NC]
RewriteCond %{QUERY_STRING} !.+
RewriteCond /var/www/var/turbocache/magento/default/%1.html -f
RewriteRule .* var/turbocache/magento/default/%1.html [L]

Thanks so far!

if ($http_cookie ~ "store=default"){
    set $rule_0 1$rule_0;
}
if ($http_cookie !~ "artio_mturbo=.*"){
    set $rule_0 2$rule_0;
}
if ($uri ~ "^/magento/$"){
    set $rule_0 3$rule_0;
}
if ($args !~ ".+"){
    set $rule_0 4$rule_0;
}
if (-f /var/ww/var/turbocache/default.html){
    set $rule_0 5$rule_0;
}
if ($rule_0 = "54321"){
    rewrite /.* /var/turbocache/default.html last;
}
if ($http_cookie ~ "store=default"){
    set $rule_1 1$rule_1;
}
if ($http_cookie !~ "artio_mturbo=.*"){
    set $rule_1 2$rule_1;
}
if ($uri ~* "/magento/(.*).html$"){
    set $rule_1 3$rule_1;
}
if ($args !~ ".+"){
    set $rule_1 4$rule_1;
}
if (-f /var/www/var/turbocache/magento/default/%1.html){
    set $rule_1 5$rule_1;
    set $bref_1 $1;
}
if ($rule_1 = "54321"){
    rewrite /.* /var/turbocache/magento/default/$bref_1.html last;
}
if ($http_cookie !~ "artio_mturbo=.*"){
    set $rule_2 1$rule_2;
}
if ($uri ~ "^/magento/default(/|)$"){
    set $rule_2 2$rule_2;
}
if ($args !~ ".+"){
    set $rule_2 3$rule_2;
}
if (-f /var/www/var/turbocache/default.html){
    set $rule_2 4$rule_2;
}
if ($rule_2 = "4321"){
    rewrite /.* /var/turbocache/default.html last;
}
if ($http_cookie !~ "artio_mturbo=.*"){
    set $rule_3 1$rule_3;
}
if ($uri ~* "^/magento/default/(.*).html$"){
    set $rule_3 2$rule_3;
}
if ($args !~ ".+"){
    set $rule_3 3$rule_3;
}
if (-f /var/www/var/turbocache/magento/default/%1.html){
    set $rule_3 4$rule_3;
    set $bref_1 $1;
}
if ($rule_3 = "4321"){
    rewrite /.* /var/turbocache/magento/default/$bref_1.html last;
}
if ($http_cookie !~ "artio_mturbo=.*"){
    set $rule_4 1$rule_4;
}
if ($uri ~ "^/magento/$"){
    set $rule_4 2$rule_4;
}
if ($args !~ ".+"){
    set $rule_4 3$rule_4;
}
if (-f /var/www/var/turbocache/default.html){
    set $rule_4 4$rule_4;
}
if ($rule_4 = "4321"){
    rewrite /.* /var/turbocache/default.html last;
}
if ($http_cookie !~ "artio_mturbo=.*"){
    set $rule_5 1$rule_5;
}
if ($uri ~* "/magento/(.*).html$"){
    set $rule_5 2$rule_5;
}
if ($args !~ ".+"){
    set $rule_5 3$rule_5;
}
if (-f /var/www/var/turbocache/magento/default/%1.html){
    set $rule_5 4$rule_5;
    set $bref_1 $1;
}
if ($rule_5 = "4321"){
    rewrite /.* /var/turbocache/magento/default/$bref_1.html last;
}

Hope it will work ,good luck。

Here is a converter that give you this from your htaccess. This may give you a solid first base. After that, if you have further question please feel free to write them.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM