将Apache .htaccess转换为Nginx

时间:2011-09-26 19:46:52

标签: apache .htaccess nginx rewrite

我有一个Magento插件的以下.htaccess代码,有人可以帮助我将其转换为有效的Nginx重写吗?我有一段非常艰难的时间。这是一个重写和缓存Magento URL的插件。

该模块的原始编辑无法帮助我。我确信有很多人使用Nginx并希望使用这个插件功能!

# 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]

到目前为止感谢!

2 个答案:

答案 0 :(得分:3)

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;
}

希望它能奏效,祝你好运。

答案 1 :(得分:1)

这是一个converter,可以从您的htaccess中获取此信息。这可能会给你一个坚实的基础。在此之后,如果您有进一步的问题,请随时写下来。