douke9379 2011-04-19 20:07
浏览 48
已采纳

帮助重写网址[复制]

Possible Duplicate:
Please URL Rewrite in php

I would like visitors to access the page by typing www.site.com/12 instead of www.site.com/room/doorstep.php?page_id=12

The IDs are many so i cannot create folders. What is the code needed to do this? I am trying to do this through .htaccess but I have not been successfull. Please help me with this.

Dennis.

  • 写回答

2条回答 默认 最新

  • doudui5753 2011-04-19 20:10
    关注

    The problem with the www.site.com/12 setup, is it makes it a bit tricky to do, as if you want to actually add a physical page called 1000 your setup may not work right (which may also depend on multiviews). Instead I would steer away from that and do something like:

    www.site.com/room/12 or www.site.com/room/id/12

    The .htaccess redirect for that would be something like:

    RewriteRule ^room/id/(.*)$ room/doorstep.php?page_id=$1 [L]
    

    That should give you the example you need to get the show on the road.


    EDIT

    What might even be better is just match a number:

    RewriteRule ^room/id/([0-9]+)$ room/doorstep.php?page_id=$1 [L]
    

    Which would only return true if a number was passed, since that is what your ID's seem to consist of.

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

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?