开发者社区> 问答> 正文

nginx rewrite 伪静态? 400 报错

nginx rewrite 伪静态? 400 报错

我想把http://www.xushenhang.com/course/vClassCourseListForJunior.jsp?stageId=1&gradeId=0&subId=0&seId=0&sctpId=1&courseName=0做伪静态,实现效果如下:

http://www.xushenhang.com/course/100010.html,应该怎样实现呢?下面是我做的配置


   location /course/ {
   if ($query_string = "stageId=(.*)&gradeId=(.*)&subId=(.*)&seId=(.*)&sctpId=(.*)&courseName=(.*)"){
     rewrite "^/(.*)$" http://$host/$1$2$3$4$5$6.html? permanent;
     }
    }

请求帮助

展开
收起
爱吃鱼的程序员 2020-05-29 19:48:05 478 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

    rewrite ^(.*)vClassCourseListForJunior-([0-9]+)-([0-9]+)-([0-9]+)-([0-9]+)-([0-9]+)-([0-9]+)\.html$ $1vClassCourseListForJunior.jsp?stageId=$2&gradeId=$3&subId=$4&seId=$5&sctpId=$6&courseName=$7;

    假如我这样写的话访问http://www.xushenhang.com/course/vClassCourseListForJunior-1-1-0-0-2-0.html就会显示http://www.xushenhang.com/course/vClassCourseListForJunior.jsp?stageId=1&gradeId=0&subId=0&seId=0&sctpId=1&courseName=0的内容,这不是我想要的效果

    ######因为我访问的 http://www.xushenhang.com/course/vClassCourseListForJunior-1-1-0-0-2-0.html并不是URL自动生成的######写反了######

    引用来自“Feng_Yu”的评论

    写反了
            rewrite ^(.*)/vClassCourseListForJunior?stageId=([0-9])&gradeId=([0-9])&subId=([0-9])&seId=([0-9])&sctpId=([0-9])&courseName=([0-9])$ $1vClassCourseListForJunior-$2-$3-$4-$5-$6-$7.html permanent; 我反过来写,但是没生效,这里有什么错误吗?请求帮助######回复 @小丑阿航 : 这个你看官方文档不就知道了。 http://nginx.org/en/docs/http/ngx_http_rewrite_module.html######回复 @Feng_Yu : 就是‘rewrite 重写成静态 原来的动态;’ 这种格式吗?######你要重写的URL写前面,实际访问的URL是后面的参数。懂了吧。也就是你的伪静态访问规则应该是在前面的。所以你写反了
    2020-05-29 19:48:06
    赞同 展开评论 打赏
问答分类:
问答标签:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
《Nginx 代理系统常用手册》 立即下载
CentOS Nginx PHP JAVA 多语言镜像使用手 立即下载
CentOS Nginx PHP JAVA多语言镜像使用手册 立即下载