我正在使用Nginx,我想用以下两个参数重写所有网址:
title=%E7%89%B9%E6%AE%8A
和
from=(any datatime)
到主页。
我不知道如何写规则,有人会帮助我吗?
编辑:
我想重写网址:
http://example.com/index.php?days=30&from=20120122083408&limit=250&title=%E7%89%B9%E6%AE%8A
或
http://example.com/index.php?from=20120622063000&limit=20&title=%E7%89%B9%E6%AE%8A
或
http://example.com/index.php?from=20030422063000&title=%E7%89%B9%E6%AE%8A
到
http://example.com
答案 0 :(得分:2)
Nginx不支持逻辑AND操作,但我们可以使用“小黑客”: 这应该可以帮到你:
location = /index.php {
set $redirect "";
# if we have get parameter "title":
if ( $arg_title ) {
set $redirect "Y";
}
# if we have get paramter "from":
if ( $arg_from ) {
set $redirect "${redirect}ES";
}
# Now in the variable $redirect should be a word "YES":
if ( $redirect = YES ) {
rewrite ^ / last;
}
....
}
P.S。您还可以使用302重定向,直接将用户移至 / 。