Nginx URL rewrite search?qu003dstring (opencart)
·
回答问题
我正在尝试做
http://site.com/index.php?route=product/search&filter_name=QUERY
至
http://site.com/search?=QUERY
这是我的规则;这没用。
rewrite ^/search?q=(.*)?$ /index.php?route=product/search&filter_name=$1 last;
Answers
Nginx 不允许你匹配查询字符串,而是它有一个$args变量和如果-s。您可以将其结合起来,使示例像这样工作:
(使用 nginx if else 语句更新)
location /search {
if ($args ~ "q=(?<q>.*)?") {
rewrite ^ /index.php?route=product/search&filter_name=$q last;
}
# Else (if no search query entered from form)
rewrite ^ /index.php?route=product/search last;
}
但是由于if -s 在 nginx 配置中被认为是邪恶的,因此您应该(在您的情况下)使用try_files:
location /search
try_files $uri /index.php?route=product/search&filter_name=$arg_q;
}
更多推荐

所有评论(0)