【问题标题】:Nginx rewrite - not workingNginx 重写 - 不工作
【发布时间】:2017-09-01 13:17:40
【问题描述】:

我有简单的 nginx 重写,我无法开始工作。

我有这个网址:

https://example.com/accessories/3427-tote-bag-grey-212345050033.html

我想重定向到:

https://example.com/dk/accessories/3427-tote-bag-grey-212345050033.html

我的 nginx 配置:

location / {
  index /index.php;

  rewrite ^/dk/$1/$2.html /$1/$2.html last;
 }

这里有什么想法是错误的吗?

【问题讨论】:

    标签: nginx


    【解决方案1】:

    $1 和 $2 用于捕获。您必须使用模式与组一起创建捕获

    试试下面

    location / {
      index /index.php;
    
      rewrite ^/([^/]+)/([^/]+).html$ /dk/$1/$2.html last;
     }
    

    或者您可以执行以下操作

    location / {
      index /index.php;
      location /accessories/ {
         alias <yourroot>/dk/accessories/;
      }
     }
    

    【讨论】:

    • 你的重写规则应该是其他方式吗? rewrite ^/([^/]+)/([^/]+).html$ /dk/$1/$2.html last;
    • @abskmj,确实如此。谢谢!
    • 索引应始终为index index.php;
    猜你喜欢
    • 1970-01-01
    • 2012-04-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多