在PHP中实现永久链接的有效方法

Chr*_*min 0 php database url rewrite title

实现php驱动的永久链接的最有效方法是什么?

基本上我想将数据库访问减少到最低限度.

重定向到存储在数据库中的id的最佳方法是什么?

gna*_*arf 8

您可以像SO一样使用基于数据库ID的URL:

http://stackoverflow.com/questions/1265061/efficient-way-to-realize-permalinks-in-php
Run Code Online (Sandbox Code Playgroud)

要么

http://stackoverflow.com/questions/1265061
Run Code Online (Sandbox Code Playgroud)

都去了同一个地方.

这通常是通过某种mod_rewrite从.htaccess重定向到你的php文件来完成的.

RewriteRule ^/questions/([0-9]+)/?.*$ /questions.php?id=$1
Run Code Online (Sandbox Code Playgroud)

重写规则会丢弃ID之后的所有内容 - 所以你甚至可以去

http://stackoverflow.com/questions/1265061/not-the-questions-title-anymore
Run Code Online (Sandbox Code Playgroud)

你仍然到达目的地.当你在php中生成链接时,你会想要将"标题slu"添加到实际的URL'链接' - 这将改善你的搜索引擎友好性......