0

I have 2 websites,

http://localhost/bb -- phpbb

http://localhost/dp -- Drupal

I wish to redirect $server_name/bb/ucp.php?mode=logout&sid=xxxxx to $server_name/dp/user/logout, the sid should be ignored.

I've tried this:

location /bb/
{
    index index.php;
    if ($query_string ~* "mode=logout$")
    {
        rewrite ^/bb/ucp\.php http://$server_name/dp/user/logout redirect;
    }
}

It seems not working. Could anyone help? Thanks.


I tried this too:

location /bb/
{
    index index.php;
    if ($arg_mode ~* "logout") ## and = instead of ~* too.
    {
        rewrite ^/bb/ucp\.php http://$server_name/dp/user/logout redirect;
    }
}

but it doesn't work either.


Current Whole config:

server {
    listen       80;
    server_name  localhost;
    add_header X-Frame-Options "SAMEORIGIN";

    client_max_body_size 500M;
    root   /var/www;

    location / {
        index  index.html index.htm index.php;
        try_files $uri @rewrite;
    }

    location /bb/
    {
        index index.php;
        if ($arg_mode = "logout")
        {
            rewrite ^/bb/ucp\.php http://$server_name/dp/user/logout redirect;
        }
    }

    location @rewrite {
        # needed by Drupal
        rewrite ^/([^/]*)/(.*)(/?)$ /$1/index.php?q=$2&$args;
    }

    location ~ \.php$ {
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        include fastcgi.conf;
        fastcgi_param PATH_INFO $fastcgi_path_info;
    }
}

(Doesn't work as expected)

hlx98007
  • 338
  • 1
  • 4
  • 11

2 Answers2

1

You should just check the argument value directly.

if ($arg_mode = "logout") {
Michael Hampton
  • 244,070
  • 43
  • 506
  • 972
0

You can use direct argument check:

if ($arg_mode = "logout")
{
    rewrite ^/bb/ucp\.php http://$server_name/dp/user/logout redirect;
}

But your approach seems to be legit as well except a wrong regexp. You have a $ sign at the end meaning the end of a line while in your example you have $server_name/bb/ucp.php?mode=logout&sid=xxxxx where logout is definitely is not at the end.

Glueon
  • 3,664
  • 2
  • 24
  • 32