vde*_*nne 1 php sql url user-experience
我有一个数据库,其中包含一个名为带有字段标题的歌曲的表.现在,如果我的网址是(xxx =歌曲的标题),则apache会默默地重定向到类似于:的页面.http://www.foo.com/songs/xxx/song.php?title=xxx
为了修饰URL我将空格转换为下划线(因为我知道某些浏览器显示%20而不是空格,而不是%20实际上%20user%20友好%20ya%20知道20%%20i%20mean).
如果标题包含空格和下划线(例如DJ_underscore fx)并且脚本将其转换DJ_underscore_fx为sql,则会出现问题:
select * from songs where songs.title=xxx
Run Code Online (Sandbox Code Playgroud)
找不到它.
这里的草图更具体:
name_of the song- >
name_of_the_song)<a
href="/songs/name_of_the_song">name_of_the_song</a>)/songs/name_of_the_son- >
/song.php?title=name_of_the_song)select * from songs where songs.title=name_of_the_song)OK你看,有一个在看起来像数据库的条目name_of_the_song,但name_of the song.
如何管理整体,以便我的URL保持清晰,标题字段不限于一定数量的值(可以有空格,下划线,破折号,以及任何东西)?
使用类似的/1234/name-of-page/地方1234是该行的主键ID,并name-of-page通过脚本忽略.
这会直接指向表中条目的主键,这将为您带来以下好处:
SELECT查询.您可能会注意到StackOverflow本身就是这样做的:
/questions/8211267/user-friendly-urls-reliable-with-the-database/
这可能会被重写为:
question.php?id=8211267
| 归档时间: |
|
| 查看次数: |
526 次 |
| 最近记录: |