0

我想摆脱这些工作规则

location = /contact {
  rewrite ^(.*)$ /index.php?v=contact last; break;
}

location = /terms {
  rewrite ^(.*)$ /index.php?v=terms last; break;
}

location = /faq {
  rewrite ^(.*)$ /index.php?v=faq last; break;
}

location = /twitter {
  rewrite ^(.*)$ /index.php?v2=twitter last; break;
}

location = /facebook {
  rewrite ^(.*)$ /index.php?v2=facebook last; break;
}

location = /login {
  rewrite ^(.*)$ /index.php?v2=login last; break;
}

location = /privacy {
  rewrite ^(.*)$ /index.php?v=privacy last; break;
}

像这样

location / {
  try_files $uri $uri/ =404;
  rewrite ^/(contact|privacy|terms|faq)$ /index.php?v=$1 last;
  rewrite ^/(twitter|facebook|login)$ /index.php?v2=$1 last; break;
}

但问题是“联系”、“条款”、“隐私”、“推特”、“脸书”页面工作正常,但“隐私”和“登录”页面抛出 404 错误

没有其他涉及“登录”和“隐私”的重写规则

4

1 回答 1

1

实际上我不喜欢这两种方法,它可能有效,但它并不是最好的编写方法,所以让我们尝试一些不同的方法。

location *~ ^/(contact|privacy|terms|faq)/?$ {
    try_files $uri $uri/ /index.php?v=$1;
}
location *~ ^/(twitter|facebook|login)/?$ {
    try_files $uri $uri/ /index.php?v2=$1;
}
location / {
    try_files $uri $uri/ /index.php;
}

o 我从来没有听说过last; break;它可能只是因为 nginx 忽略了它的最后一部分,它是 alast或 a break

于 2013-07-21T22:38:11.897 回答