在nginx为站点带参数的网址重定向到不同的新页面

问题:将php的站点静态化后,搜索引擎中的一些页面想跳转到新的静态页如,如 post.php?id=5 重定向到 post35ta.html,post.php?id=7 重定向到 postd26t.html。

处理:可在nginx的站点配置文件中,设置按条件301跳转,如:

location = /post.php {
    if ($arg_id = 5) {
        return 301 http://liujia.anqun.org/post35ta.html;
    }
    if ($arg_id = 7) {
        return 301 http://liujia.anqun.org/postd26t.html;
    }
                                                                                                                    
    try_files  $uri /index.html;
}

参考:

标签: nginx, 跳转

添加新评论