Nginx判断搜索引擎来路和蜘蛛跳转并添加用户访问记录-自用跳转代码
Nginx判断来源(来路) 在 Nginx 中,你可以使用$http_referer变量来判断请求的来源(来路),并进行相应的跳转。$http_referer变量包含了请求的来源页面的 URL。 以下是一个示例配置,演示如何使用 Nginx 判断来路并进行跳转: location / { # 检查来路是否为特定的来源 if ($http_referer ~* "example.com") { # 来自 example.com 的请求将被重定向到另一个地址 return 301 https://www.360baiduseo.com$request_uri; } } 在if语句中,我们使用正则表达式匹配$http_referer,如果来路是example.com,则通过return语句将请求重定向到https://360baiduseo.com。如果没有匹配到特定的来源,Nginx 将允许正常访问。 需要注意的是,使用if语句可能会对性能产生一些影响,因此在实际使用时,建议根据需求进行优化。另外,Nginx 还支持更多的条件判断和重定向选项,你可以根据具体情况进行配置。 搜索引擎来路跳转 下面是根据搜索引擎来路判断跳转代码: # 保留原程序的伪静态规则: if (!-e $request_filename){ rewrite ^/html/(.*)$ /index.php?$1 last; } #判断搜索引擎来路跳转开始: location / { if ($http_referer ~* "baidu.com|sogou.com|so.com|sm.cn|bing.com|toutiao.com") { rewrite ".*" https://www.360baiduseo.com/; } } 通过上面的代码大不知到大家有没有发现,有时蜘蛛的来路也是搜索引擎,比如Baiduspider的referer是www.baidu.com,那么怎么可以让用户跳转,蜘蛛却不跳转呢? Nginx判断蜘蛛 location / { if ($http_user_agent ~* "Baiduspider|360Spider|bingbot|Googlebot|Sogou web spider|spider") { rewrite ^/html/(.*)$ /index.php?$1 last; } } Nginx中if语句里的AND/&&/OR 多重判断 if (来路==搜索引擎 and 是蜘蛛){ rewrite ^/html/(.*)$ /index.php?$1 last; } nginx 语句中是不存在 and 的那么如何实现呢? ...