【问题标题】:How to implement slug replacing id's in the URL如何在 URL 中实现 slug 替换 id
【发布时间】:2017-05-22 18:49:50
【问题描述】:

目前我有一个主页 (index.php),其中包含指向另一个页面 (story.php) 的多个链接。为了加载不同的故事,我的超链接如下

<a  href=”story.php?cat_id=0&n_id=2”>Best Mobile Phones of 2016</a>

如您所见,网址类似于:story.php?cat_id=0&amp;n_id=2

我想将 URL 更改为像 Best-Mobile-Phones-of-2016 这样的 Slug。这些 slug 作为表中的字段存在。

现在我的问题是,如果我想使用 slugs 而不是通过 id 来提供页面,那么我应该怎么做?我的意思是我的超链接应该如何在 index.php 中使用不同的故事。

希望您能理解我的问题。在这方面的任何帮助都将非常感激。

【问题讨论】:

    标签: php html seo slug


    【解决方案1】:

    SEO 友好链接基本上是这样的:story/Best-Mobile-Phones-of-2016 而不是 story.php?cat_id=0&amp;n_id=2
    现在,当用户浏览该网站时,您的 .htaccess 将该网址重写为例如story.php?storyID=Best-Mobile-Phones-of-2016。您的算法必须确定哪个 cat_idn_idstoryID 相关联。

    您还可以将 cat_idn_id 附加到您的 storyIDstory.php?storyID=Best-Mobile-Phones-of-2016_0_2。那么你的算法就可以轻松炸掉你的storyID

    希望对你有所帮助。

    【讨论】:

    • 谢谢@Luca。我想我得到了答案。你为我指明了正确的方向。
    猜你喜欢
    • 2012-10-02
    • 2012-12-30
    • 2014-01-07
    • 2020-04-24
    • 2011-04-21
    • 2014-10-23
    • 2022-12-05
    • 2021-03-19
    • 1970-01-01
    相关资源
    最近更新 更多