dongnong3019 2012-02-25 04:07
浏览 48
已采纳

尝试使用.htaccess重写进行分页

So I was pretty proud of myself because for the first time ever, I actually figured out how to update the .htaccess file without asking for help (a new milestone for me).

Here's what I added:

RewriteRule albums/(.*)/(.*)/(.*)/ albums.php?language=$1&searchindex=$2&searchparameterdata=$3

that worked to translate my links to: www.my domain.com/albums/en/music/beatles/

But then.. along came pagination and I'm stumped again. On clicking my next page, it now appends to the above url like such..

beatles/?language=en&locale=us&page=2&searchindex=music&searchparameter=keywords&searchparameterdata=beatles&

Is this something I can correct in my .htaccess.. keeping the format of my working url and still letting pagination work?

  • 写回答

2条回答 默认 最新

  • duan0514324 2012-02-25 04:43
    关注

    I think you are making it too hard for yourself; why not send all parameters in a single parameter and let php decide what to do with it? Try this:

    RewriteRule albums/(.*) albums.php?parameters=$1 [L]
    

    And then in your php:

    parse_str($_GET['parameters], $parameters);
    do_stuff($parameters['searchindex'], $parameters['page'], ...);
    

    nice and easy :)

    check out http://php.net/manual/en/function.parse-str.php for the manual on parse_str(), do_stuff() is obviously invented ;)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误