我需要一些关于nginx regex重写的帮助。
此
https://www.website.com/downloads.php?do=file&id=4798
要
https://www.website.com/index.php?resources/4798/
此
https://www.website.com/showthread.php?t=4449128
要
https://www.website.com/index.php?threads/4449128/
这(TRICKY ONE)。
https://www.website.com/forumdisplay.php?f=12&prefixid=8
要
https://www.website.com/forums/pc-probs.12/?prefix_id=8
谢谢大家的帮助。
@Miguel Mota
标记
答案 0 :(得分:1)
试试这个。这基于您的示例。
location / {
# A
if ($args ~* "id=(\d+)") {
set $id $1;
set $args '';
rewrite ^/downloads\.php(.*)$ /index.php?resources/$id/ permanent;
}
# B
if ($args ~* "t=(\d+)") {
set $t $1;
set $args '';
rewrite ^/showthread.php(.*)$ /index.php?threads/$t/ permanent;
}
# C
if ($args ~* "prefixid=(\d+)") {
set $pfid $1;
}
if ($args ~* "f=(\d+)") {
set $f $1;
set $args '';
rewrite ^/forumdisplay.php(.*)$ /forums/pc-probs.$f/?prefix_id=$pfid/ permanent;
}
}