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)

  • Usually you want to do the opposite. Testing query strings is a pain. – Xavier Lucas Oct 6 '14 at 21:43
1

You should just check the argument value directly.

if ($arg_mode = "logout") {
| improve this answer | |
  • Sorry, this change does not change anything. – hlx98007 Oct 6 '14 at 21:43
  • @hlx98007 It should work. Post your whole config and the observed behaviour so. – Xavier Lucas Oct 6 '14 at 22:15
  • I've put the whole config here. I suspect the @rewrite is messing with me but not too sure on how to change. – hlx98007 Oct 7 '14 at 0:39
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.

| improve this answer | |
  • I changed the code but it won't work. – hlx98007 Oct 7 '14 at 0:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.