.htaccess - 将htaccess转换成 Nginx

我无法将htaccess规则转换为Nginx rewrite,以下是我的内容:


RewriteRule ^$ /cgi-bin/index.cgi [L]
RewriteRule ([0-9A-Za-z]{12})-del-([0-9A-Za-z]+)/.+$ /cgi-bin/index.cgi?del=$1-$2 [L]

RewriteCond %{REQUEST_FILENAME} !-f

RewriteRule ^([0-9A-Za-z]{12})(.html?|$)$ /cgi-bin/index.cgi?op=download1&id=$1 [L]
RewriteRule ^([0-9A-Za-z]{12})(/.+|.html?|$) /cgi-bin/index.cgi?op=download1&id=$1&fname=$2 [L]
RewriteRule ^([0-9A-Za-z-_]{4,64})/([0-9A-Za-z]{12})$ /cgi-bin/index.cgi?op=download1&usr_login=$1&id=$2 [L]
RewriteRule ^([0-9A-Za-z-_]{4,64})/([0-9A-Za-z]{12})(/.+|.html?|$) /cgi-bin/index.cgi?op=download1&usr_login=$1&id=$2&fname=$3 [L]

#RewriteRule ^Reseller.html$ /cgi-bin/Templates/Pages/english/Reseller.html [L]
RewriteRule ^checkfiles.html$ /cgi-bin/index.cgi?op=checkfiles [L]
RewriteRule ^contact.html$ /cgi-bin/index.cgi?op=contact [L]
RewriteRule ^premium.html$ /cgi-bin/index.cgi?op=payments [L]
RewriteRule ^login.html$ /cgi-bin/index.cgi?op=login [L]
RewriteRule ^catalogue(.*).html$ /cgi-bin/index.cgi?op=catalogue&date=$1 [L]
RewriteRule ^news([0-9]*).html$ /cgi-bin/index.cgi?op=news&page=$1 [L]
RewriteRule ^n([0-9]+)-.*.html$ /cgi-bin/index.cgi?op=news_details&news_id=$1 [L]
RewriteRule ^free([0-9]+).html$ /cgi-bin/index.cgi?op=registration&aff_id=$1 [L]
RewriteRule ^users/([0-9A-Za-z-_]{4,64})/?([0-9]+|$) /cgi-bin/index.cgi?op=user_public&usr_login=$1&fld_id=$2 [L,NC]
RewriteRule ^embedmp3-([0-9A-Za-z]{12}).html$ /cgi-bin/index.cgi?op=mp3_embed&file_code=$1 [L]
RewriteRule ^embedmp4-([0-9A-Za-z]{12}).html$ /cgi-bin/index.cgi?op=mp32_embed&file_code=$1 [L]
RewriteRule ^box$ /cgi-bin/index_box.cgi [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([0-9A-Za-z-_]{4,64})(/[^/]*/?|$)$ /cgi-bin/index.cgi?op=user_public&usr_login=$1&fld=$2 [L,NC]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([a-z0-9-_]+).html(.*) /cgi-bin/index.cgi?op=page&tmpl=$1$2 [L]

时间:

Rewrite 规则的编写方式与Nginx非常相似:http://wiki.nginx.org/HttpRewriteModule#rewrite

你可以很容易地创建一个Php脚本来解析你的旧htaccess,我将这个用于PRestashop规则:

$content = $_POST['content'];


 $lines = explode(PHP_EOL, $content);
 $results = '';

 foreach($lines as $line)
 {
 $items = explode(' ', $line);

 $q = str_replace("^","^/", $items[1]);

 if (substr($q, strlen($q) - 1) !== '$') $q .= '$';

 $buffer = 'rewrite"'.$q.'""'.$items[2].'" last;';

 $results .= $buffer.PHP_EOL;
 }

 die($results);

...