NGINX重写动态页面 [英] NGINX Rewrites dynamic pages
本文介绍了NGINX重写动态页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要有关nginx regex重写的帮助.
I need some help with nginx regex rewrites.
这个
https://www.website.com/downloads.php?do=file&id=4798
TO
https://www.website.com/index.php?resources/4798/
这个
https://www.website.com/showthread.php?t=4449128
TO
https://www.website.com/index.php?threads/4449128/
这(棘手的人).
https://www.website.com/forumdisplay.php?f=12&prefixid=8
TO
https://www.website.com/forums/pc-probs.12/?prefix_id=8
谢谢大家的帮助.
@Miguel Mota
@Miguel Mota
标记
推荐答案
尝试一下.这根据您的示例起作用.
Try this. This works based on your examples.
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;
}
}
这篇关于NGINX重写动态页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文