dongzong2017 2015-07-27 19:09
浏览 23
已采纳

mod重写 - 有很好的网址,但仍然从数据库动态构建菜单

I am creating my menu dynamically from a database. I started by appending an id to the urls which I used to identify the page in the database and then get all urls from the subpages and so on..

so I had a lot of ids like this www.page.com/somefolder/pagename.php?id=10, where 10 is the id of the page and is the parent_id for a number of other pages.

Now I use mod rewrite to get nicer urls. So the above url is now www.page.com/pagename.php , which is mapped to the original url. My pagenames are all gonna be unique.

The question: Do I have to do this for each and every url, since each url needs an id as query string or is there a better way to combine mod rewrite with dynamically generating a menu?

  • 写回答

1条回答 默认 最新

  • dpmopn8542 2015-07-27 19:49
    关注

    No, not for every URL, but you will need to do this the other way around.

    Turn the rewrite engine on

    RewriteEngine on 
    

    Build a path to match against using a dynamic 'case' in brackets..

    RewriteRule ^/?somefolder/page/([0-9]+)/?$
    

    .. complete the rule with the rewritten URL, using $1 for the 'case'

    /somefolder/pagename.php?id=$1 [L]
    

    Put it all together using [L] to signify the 'last' rule to execute.

    RewriteRule ^/?somefolder/page/([0-9]+)/?$ /somefolder/pagename.php?id=$1 [NC,L]
    

    This will rewrite /somefolder/page/12345/ to /somefolder/pagename.php?id=12345

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!