将htaccess规则转换为nginx规则

时间:2015-11-13 13:23:52

标签: apache .htaccess mod-rewrite nginx

我有这些apache(htaccess)规则,我想将它们转换为nginx规则。我尝试了很多组合但是徒劳无功。

您有以下规则:

RewriteRule ^candybooru/_images/([0-9a-f]{2})([0-9a-f]{30}).*$  /candybooru/images/$1/$1$2
RewriteRule ^candybooru/_thumbs/([0-9a-f]{2})([0-9a-f]{30}).*$  /candybooru/thumbs/$1/$1$2
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^candybooru/(.*)$ /candybooru/index.php?q=$1&%{QUERY_STRING}

2 个答案:

答案 0 :(得分:1)

也许您可以使用此页面转换规则:http://winginx.com/en/htaccess

转换后的规则是:

# nginx configuration
location / {
rewrite "^/candybooru/_images/([0-9a-f]{2})([0-9a-f]{30}).*$" /candybooru/images/$1/$1$2;
rewrite "^/candybooru/_thumbs/([0-9a-f]{2})([0-9a-f]{30}).*$" /candybooru/thumbs/$1/$1$2;
}
location /candybooru {
rewrite ^/candybooru/(.*)$ /candybooru/index.php?q=$1&$query_string;
}

答案 1 :(得分:1)

结帐try_files。我还没有对此进行过测试,但它应该有效(或接近):

location /candybooru/ {
    location ~ "^/candybooru/_(images|thumbs)/([0-9a-f]{2})([0-9a-f]{30})" {
        try_files /candybooru/$1/$2/$2$3 /candybooru/index.php?q=$2&$query_string;
    }
}