htaccess to nginx url redirection script (phpbb to xenforo)

234 Views Asked by At

I have these htaccess rules for redirecting phpbb urls to xenforos friendly urls

    RewriteCond %{QUERY_STRING} (^|&)t=([0-9]+)(&|$) [NC]
    RewriteRule ^viewtopic\.php$ /threads/%2/? [L,R=301,NC]

    RewriteCond %{QUERY_STRING} f=(\d+)$ [NC]
    RewriteRule ^(viewforum\.php|viewtopic\.php)$ /forums/%1/? [L,R=301,NC]

    RewriteCond %{QUERY_STRING} (^|&)p=([0-9]+)(&|$) [NC]
    RewriteRule ^viewtopic\.php$ /posts/%2/? [L,R=301,NC]

which redirects phpbb urls to xenforo friendly urls like

"/viewtopic.php?t=X" will redirect to "/threads/X/" and
"/viewtopic.php?p=X" will redirect to "/posts/X/" 

etc

What would its equivalent be in nginx? I tried online converters and even Plesk htaccess to nginx rules, no luck.

Plesk outputs this

if ($args ~* "(^|&)t=([0-9]+)(&|$)"){
    set $rule_0 1$rule_0;
    set $bref_2 $2;
    set $bref_undefined $undefined;
}
if ($rule_0 = "1"){
    rewrite ^/viewtopic\.php$ /threads/$bref_2/? permanent;
}

But it doesn't work. Help please.

1

There are 1 best solutions below

0
STN On

Someone on the xenforo forum helped. I edited his script to make it work. This is the Nginx rewrite rule that works

if ($query_string ~* "(^|&)t=([0-9]+)(&|$)"){  
rewrite ^/viewtopic\.php$ /threads/$arg_t/? redirect;  }

if ($query_string ~* "f=(\d+)$"){  
rewrite ^/(viewforum\.php|viewtopic\.php)$ /forums/$arg_f/? redirect;  }

if ($query_string ~* "(^|&)p=([0-9]+)(&|$)"){  
rewrite ^/viewtopic\.php$ /posts/$arg_p/? redirect;  }