[英]Redirect with nginx for all id less than a fixed value, how?
In nginx config file need to redirect all articles with $id less than a fixed value. 在nginx配置文件中,需要重定向$ id小于固定值的所有文章。 $ID - i am getting from the query string. $ ID-我从查询字符串中获取。 But nginx does not support comparison operators "<", ">". 但是nginx不支持比较运算符“ <”,“>”。 What to do ? 该怎么办 ? How to solve the problem? 如何解决问题? Redirect through php - not the best solution .... 通过php重定向-不是最佳解决方案....
If the value you try to compare is not too fancy you can still use regex: 如果您尝试比较的值不太合适,您仍然可以使用regex:
^(\d){1,3}$
This would Match from 0 to 999. You raise the 3 to a 5 it goes from 0 to 99999 and so on. 这将匹配从0到999。将3增大到5,它将从0变为99999,依此类推。
The problem was: Redirect pages on certain rules, with the exception of some specific 问题是:根据某些规则重定向页面,但某些特定规则除外
####
# In http section
# It is expetion pages
###
#set $stayHere 0;
map $request_uri $stayHere {
include snippets/pages.map;
}
####
# End http section
###
####
# File pages.map
###
~\/expetionPage.+ A;
~\/expetionPage2.+ A;
~\/expetionPage995Test.+ A;
####
# End File pages.map
###
####
# In server section
####
set $oldPage 0;
## Redirect For pages less 45329 in the rquest
## If it is not exeption page
if ($request_uri !~ "([1-9]\d{5,}|[5-9]\d{4}|4[6-9]\d{3}|45[4-9]\d{2}|453[3-9]\d{1}|45329)"){
set $oldPage "${stayHere}A";
}
#####
# some conditions
#####
if ($request_uri ~ ^/$) {
set $oldPage "AA";
}
if ($request_uri ~ "\/[a-zA-Z\-\/]+") {
set $oldPage "AA";
}
#####
#redirect if for my rule, if not exeption
#####
if ($oldPPage = "A"){
return 301 http://newPage.net$request_uri;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.