【问题标题】:Help Converting Apache htaccess to Nginx Rewrite rules帮助将 Apache htaccess 转换为 Nginx 重写规则
【发布时间】:2011-04-16 03:08:44
【问题描述】:

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

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

非常感谢~

【问题讨论】:

    标签: apache .htaccess nginx rewrite


    【解决方案1】:

    格式有点不对,但我认为您的原始规则是

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

    所以 Nginx 重写将是

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

    如果你read the documentation,不难。

    【讨论】:

      【解决方案2】:

      使用以下 bash 单行代码来转换 .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/;
      }
      

      【讨论】:

        猜你喜欢
        • 2014-06-30
        • 2016-08-09
        • 1970-01-01
        • 1970-01-01
        • 2021-04-04
        • 2015-06-29
        • 1970-01-01
        • 2012-03-16
        • 2016-06-18
        相关资源
        最近更新 更多