【问题标题】:Need help converting Apache2 Rewrite rules to nginx需要帮助将 Apache2 重写规则转换为 nginx
【发布时间】:2012-03-16 19:32:00
【问题描述】:

我已经成功转换了其中的大部分,但我在这两个方面有点挣扎 -

RewriteRule ^(.+)/$ http://%{HTTP_HOST}/$1 [R=301,QSA,L]

RewriteRule !^(media/(.+)|favicon.ico|robots.txt|sitemap.xml|sitemap-main.xml)$ index.php

如果有人是 nginx 重写忍者,将不胜感激:)

【问题讨论】:

    标签: apache mod-rewrite url-rewriting nginx


    【解决方案1】:

    这个:

    RewriteRule ^(.+)/$ http://%{HTTP_HOST}/$1 [R=301,QSA,L]
    

    将转换为:

    rewrite ^/(.+)/$ http://$http_host/$1 permanent;
    

    还有这个:

    RewriteRule !^(media/(.+)|favicon.ico|robots.txt|sitemap.xml|sitemap-main.xml)$ index.php
    

    将转换为:

    rewrite /!^(media/(.+)|favicon.ico|robots.txt|sitemap.xml|sitemap-main.xml)$ /index.php;
    

    你也可以使用:

    if ($rule_0 = ""){
        rewrite ^/(.+)/$ http://$http_host/$1 permanent;
    }
    if ($rule_0 = ""){
        rewrite /!^(media/(.+)|favicon.ico|robots.txt|sitemap.xml|sitemap-main.xml)$ /index.php;
    }
    

    文档:http://wiki.nginx.org/HttpRewriteModule

    发件人:http://www.anilcetin.com/convert-apache-htaccess-to-nginx/

    【讨论】:

    • 谢谢 - 感激不尽。我会支持你...但我还没有足够的声誉!
    • 你可以投票也可以接受答案:meta.stackexchange.com/questions/5234/…
    • 没问题,您接受的答案比例越高,您获得高质量答案的机会就越大。欢迎使用 StackOverFlow。
    • 哦,太好了,谢谢。现在有足够的特权来支持答案 - 所以我已经这样做了:)
    猜你喜欢
    • 1970-01-01
    • 2015-06-29
    • 1970-01-01
    • 2011-04-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-30
    • 2016-08-09
    相关资源
    最近更新 更多