Nginx将vBulletin URL重定向至XenForo遇阻:ID与文本顺序调换问题
Nginx实现vBulletin友好URL到XenForo的301重定向
针对vBulletin迁移到XenForo时的URL重定向问题——旧URL为/forums/xxx.php?ID-文本格式,新URL为/xxx/文本.ID/格式,且ID与文本顺序调换,可通过以下Nginx正则规则实现精准重定向:
帖子页重定向规则
处理旧路径/forums/showthread.php?数字ID-帖子标题到新路径/threads/小写标题.数字ID/:
location ~* ^/forums/showthread.php\?(\d+)-(.+)$ { set $thread_id $1; set $thread_slug $2; # 将标题转为小写,匹配XenForo的URL格式 set_lowercase $thread_slug_lower $thread_slug; # 执行301永久重定向 rewrite ^ https://twcenter.net/threads/$thread_slug_lower.$thread_id/ permanent; }
用户页重定向规则
处理旧路径/forums/member.php?数字ID-用户名到新路径/members/小写用户名.数字ID/:
location ~* ^/forums/member.php\?(\d+)-(.+)$ { set $user_id $1; set $user_slug $2; # 将用户名转为小写 set_lowercase $user_slug_lower $user_slug; # 执行301永久重定向 rewrite ^ https://twcenter.net/members/$user_slug_lower.$user_id/ permanent; }
补充配置说明
- 保留原有非友好URL规则:继续使用你已生效的规则,覆盖
?t=ID和?u=ID格式的旧链接:
location = /forums/showthread.php { return 301 /threads/$arg_t/; } location = /forums/member.php { return 301 /members/$arg_u/; }
- 模块依赖:确保你的Nginx安装了
ngx_http_set_misc_module(提供set_lowercase指令)。如果无此模块,可忽略大小写转换(XenForo通常兼容大小写不一致的slug),或通过perl指令实现小写转换。 - 规则顺序:将重定向规则放在server块的靠前位置,优先于静态文件处理、PHP解析等规则,避免被其他location拦截匹配。
内容的提问来源于stack exchange,提问作者GrnEyedDvl
相关产品推荐
相关产品推荐

