【问题标题】:How to Redirect Traffic If User Is In a Certain Directory and There is a Query String如果用户在某个目录中并且有查询字符串,如何重定向流量
【发布时间】:2016-07-05 11:57:03
【问题描述】:

我正在尝试将具有目录 /members/ 和查询字符串 ?loggedout=true 的所有流量重定向到主页。

这是一个例子:

https://thebestsites.com/members/brian/settings/?loggedout=true

此 URL 应重定向到主页。我正在寻找使用 WordPress 插件或 Nginx 来做到这一点......有什么想法吗?我在正确的地方发布了吗?

这不起作用:

server {
    listen 80;
    server_name thebestsites.com *.thebestsites.com;
    return 301 https://thebestsites.com$request_uri;
}
server {

    listen 443;
    ssl on;
    ssl_certificate /var/www/thebestsites.com/cert/thebestsites.com.crt;
    ssl_certificate_key /var/www/thebestsites.com/cert/thebestsites.com.key;

    server_name thebestsites.com   www.thebestsites.com;


    access_log /var/log/nginx/thebestsites.com.access.log rt_cache;
    error_log /var/log/nginx/thebestsites.com.error.log;


    root /var/www/thebestsites.com/htdocs;

    location /members {
        if($arg_loggedout = true) {
            rewrite ^/members/  /  redirect;
        }
    }

    index index.php index.html index.htm;


    include common/wpfc-php7.conf;

    include common/wpcommon-php7.conf;
    include common/locations-php7.conf;
    include /var/www/thebestsites.com/conf/nginx/*.conf;
}

【问题讨论】:

  • 当然,这是可能的。请发布您的 nginx 配置,以便我们提供答案
  • 我投票结束这个问题,因为提问者不知道如何使用 systemd(请参阅他的 cmets)。

标签: wordpress nginx


【解决方案1】:

一定要使用nginx 来满足您的所有重定向需求!

if ($arg_loggedout = true) {
    rewrite ^/members/  /   redirect;
}

【讨论】:

  • 我能不能这样 if 语句只在它们位于目录成员中时才会触发?
  • #location /members/ { # if($arg_loggedout = true) { # rewrite ^/members/ / 重定向; # } #} 抛出一个错误,上面写着“nginx.service 的作业失败,因为控制进程以错误代码退出。请参阅“systemctl status nginx.service”和“journalctl -xe”f 或详细信息。”
  • 是的,if 指令也适用于位置上下文;见nginx.org/r/if。你遇到了什么错误?不要复制粘贴有关如何查看错误消息详细信息的帮助,复制粘贴错误消息本身! :-)
  • 错误信息是 Job for nginx.service failed 因为控制进程退出,错误码。请参阅“systemctl status nginx.service”和“journalctl -xe”或详细信息
  • 再次,这不是错误消息。 nginx 不会产生任何提及“systemd”的消息。如果您不知道如何启动 nginx 或获取其错误消息,那超出了您最初问题的范围(而且,肯定超出了 StackOverflow 的范围,它是关于编程,而不是系统管理)。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-10-15
  • 2014-09-09
  • 2015-11-26
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多