首页 文章

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

提问于
浏览
1

我需要将以下Apache htaccess规则转换为 Nginx Rewrite rules

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

非常感谢〜

2 回答

  • 1

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

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

    所以Nginx会重写

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

    如果你read the documentation并不难 .

  • 3

    使用以下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/;
    }
    

相关问题