帮助将Apache htaccess转换为Nginx重写规则

时间:2010-09-23 07:39:30

标签: apache .htaccess nginx rewrite

我需要将以下Apache htaccess规则转换为 Nginx重写规则

重定向301 /feed.php http://www.example.com/feed/

非常感谢〜

2 个答案:

答案 0 :(得分:3)

格式化有点偏,但我认为原来的规则是

Redirect 301 /feed.php http://www.example.com/feed/

所以Nginx重写将是

rewrite ^/feed\.php http://www.example.com/feed/ permanent;

如果你read the documentation,那就不难了。

答案 1 :(得分:1)

使用以下bash one-liner,转换.htaccess文件中的Apache Redirect行:

while read LINE; do echo -e `echo $LINE | egrep '^Redirect' | cut -d' ' -f1-2` "{\n\treturn 301 `echo $LINE|cut -d' ' -f3`;\n}"; done < .htaccess

结果,

Redirect /feed.php http://www.example.com/feed/

...行打印为以下Nginx样式:

location /feed.php {
         return 301 http://www.example.com/feed/;
}
相关问题