【问题标题】:NGINX Rewrites for a site moveNGINX 为站点迁移重写
【发布时间】:2017-06-21 19:54:27
【问题描述】:

我有一个问题,我们需要将我们的网站移动到另一个软件。

我们有以下网址设置:

Downloads / Resources
Original:
https://www.website.com/downloads.php?do=file&id=47

New:
https://www.website.com/resources/flight-update-red.47/

Forum
Original:
https://www.website.com/gen-chat-213/

New:
https://www.website.com/forums/gen-chat.213/

Thread
Original:
https://www.website.com/gen-chat-213/8281-connect-probs.html

New:
https://www.website.com/threads/connect-probs.8281/

我在论坛部分试过这个:

rewrite ^/(.*)-$/ /forums/$1.$2/ last;

但是没有运气可以请人帮忙,

谢谢

【问题讨论】:

    标签: regex url nginx url-rewriting


    【解决方案1】:

    试试这个。这基于您的示例。

       location / {
          # Downloads / Resources
          if ($args ~* "id=(\d+)") {
            set $id $1;
            set $args '';
            rewrite ^/downloads\.php(.*)$ /resources/flight-update-red.$id/ permanent;
          }
    
          # Forum
          rewrite ^/([a-z-]+)-(\d+)/$ /forums/$1.$2/ permanent;
    
          # Thread
          rewrite ^/[a-z-]+-\d+\/(\d+)-(.*)\.html$ /threads/$2.$1/ permanent;
       }
    

    【讨论】:

    • 误会对不起 - 你能帮我解决这些问题吗?来自线程的页面:https://www.website.com/gen-chat-213/8281-connect-probs-2.html https://www.website.com/gen-chat-213/8281-connect-probs-3.html https://www.website.com/gen-chat-213/8281-connect-probs-4.html .......... ......................https://www.website.com/threads/connect-probs.8281/page-2 https://www.website.com/threads/connect-probs.8281/page-3 https://www.website.com/threads/connect-probs.8281/page-4
    • 非常感谢 Miguel,您的帮助非常棒。
    • 试试这个rewrite ^/[a-z-]+-\d+\/(\d+)-([a-z-]+)-(\d+)\.html$ /threads/$2.$1/page-$3/ permanent;
    • 这对 Maguel 有效!谢谢你。我必须在线程重写之前将页面重写,否则将无法正常工作。
    • @MarkDavis 创建一个新问题并将链接发送给我
    猜你喜欢
    • 2021-03-26
    • 2013-08-29
    • 1970-01-01
    • 2011-01-17
    • 2016-05-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-15
    相关资源
    最近更新 更多