【问题标题】:htaccess to nginx url redirection script (phpbb to xenforo)htaccess 到 nginx url 重定向脚本(phpbb 到 xenforo)
【发布时间】:2020-06-10 08:27:39
【问题描述】:

我有这些 htaccess 规则用于将 phpbb url 重定向到 xenforos 友好的 url

    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]

将 phpbb url 重定向到 xenforo 友好的 url,例如

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

在 nginx 中它的等价物是什么?我尝试了在线转换器甚至 Plesk htaccess 到 nginx 规则,但没有运气。

Plesk 输出这个

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;
}

但它不起作用。请帮忙。

【问题讨论】:

标签: .htaccess nginx redirect phpbb xenforo


【解决方案1】:

xenforo 论坛上的某个人提供了帮助。我编辑了他的脚本以使其工作。这是有效的 Nginx 重写规则

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;  }

【讨论】:

    猜你喜欢
    • 2017-04-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-05
    • 1970-01-01
    • 1970-01-01
    • 2016-12-16
    • 1970-01-01
    相关资源
    最近更新 更多