duande1985 2013-01-09 10:13
浏览 20
已采纳

来自数据库的自定义PHP URL

i was running into a problem while creating a simple database and i hope you can provide me with some help ;).

The problem :

I need to create a database which contains offers (for example for hotels, holidays etc) thats no problem at all. What we want to do is to make each entry customizable with a single url that can be chosen by the author itself. For example we've got an overview page (overview.php) where all the offers are listed. Now i want to click on the first offer "Mallorca" for example which inherits the id 50. The dynamic URL would be something like "detail.php?id=50 for example, but i want to rewrite them from a individual field in my database that the author specified while creating the entry which looks as following :

Offer Name
Offer Date
Offer Price
URL (which can be anything, also blabla.htm)

The URL field should then be used to create a custom individual url for each offer - for example detail.php?id=50 would become mydomain.com/offers/mallorca.htm

I know that mod_rewrite can be consulted but i haven't figured out how to combine it to use fields from my database.

Any advice?

  • 写回答

2条回答 默认 最新

  • dtuct88226 2013-01-09 10:25
    关注

    Just ideas for You to think of or bounce off:

    1. if You left a free hand to the author to enter the URL of their own, You would have to implement a controll for the URL uniqueness, while not letting the user to save the data until the URL part for the concrete offer is really unique
    2. easier way is to only have the URLs like mydomain.com/offers/50/ - it still looks better while the implementation tooks less time
    3. at the end, You would have to write a rewrite rule to Your .htaccess, while the result depends on what way You would go (from point 1 or point 2):
      • 1: RewriteRule ^/offers/(.*)$ detail.php?url=$1 [L, QSA]
      • 2: RewriteRule ^/offers/(.*)/$ detail.php?id=$1 [L, QSA]

    If You'd go with the first option (the one You desired), You would also have to look up the offer by the URL part provided, in the second option You look up by the ID.

    Hope this helps.

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

报告相同问题?

悬赏问题

  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失