我想退出这些工作规则
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;
}
但问题是"contact"、"terms"、"privacy"、"witter"、"facebook"页面工作正常,但"privacy"answers"login"页面出现404错误。
没有其他涉及"登录"answers"隐私"的重写规则
事实上,我不喜欢这两种方法,它可能有效,但这并不是最好的编写方法,所以让我们尝试不同的方法。
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忽略了它的最后一部分,它要么是last
,要么是break
,