XF 2.1 htaccess to nginx url redirection script

Vroomm

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

Apache config:
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]

What would its equivalent be in nginx? I tried online converters and even Plesk htaccess to nginx rules, no luck.
 
I have these htaccess rules for redirecting phpbb urls to xenforos= friendly urls

Apache config:
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]

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

Code:
location / 
{ 
if ($query_string ~* "(^|&)t=([0-9]+)(&|$)"){   
   rewrite ^/viewtopic\.php$ /threads/%2/? redirect;  } 
if ($query_string ~* "f=(\d+)$"){   
   rewrite ^/(viewforum\.php|viewtopic\.php)$ /forums/%1/? redirect;  } 
if ($query_string ~* "(^|&)p=([0-9]+)(&|$)"){   
   rewrite ^/viewtopic\.php$ /posts/%2/? redirect;  }
}

Hth
 
Code:
location /
{
if ($query_string ~* "(^|&)t=([0-9]+)(&|$)"){ 
   rewrite ^/viewtopic\.php$ /threads/%2/? redirect;  }
if ($query_string ~* "f=(\d+)$"){ 
   rewrite ^/(viewforum\.php|viewtopic\.php)$ /forums/%1/? redirect;  }
if ($query_string ~* "(^|&)p=([0-9]+)(&|$)"){ 
   rewrite ^/viewtopic\.php$ /posts/%2/? redirect;  }
}

Hth

Thank you! Your script didn't work for me completely (it wouldn't pass the %2 argument), however i changed it a bit and learned about the powerful $arg in nginx. This is the script i am using now

Apache config:
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;  }
 
Thank you! Your script didn't work for me completely (it wouldn't pass the %2 argument), however i changed it a bit and learned about the powerful $arg in nginx. This is the script i am using now

Apache config:
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;  }
I'm trying this for a phpbb redirect I have now, but I'm not finding it to work properly.
 
Back
Top Bottom