【问题标题】:search engine friendly blog urls搜索引擎友好的博客网址
【发布时间】:2014-04-06 15:58:33
【问题描述】:

嘿,我正在为我的网站制作博客,我决定自己制作而不是使用第 3 方,但是我不知道如何制作 url 的 seo 友好 atm 他们就像这样 /blogpost .php?id=15 但是我希望它是 /the-title 有没有办法在没有 htaccess 的情况下做到这一点? atm 我正在使用它来制作网址'

echo '<a href="blogpost.php?id='.$row['id'].'">';

然后我使用 _GET 来获取 id,然后从数据库中获取信息,我可以用 name 替换 id 但这给了我 /blogpost.php?title=The-Title

感谢您的帮助。

【问题讨论】:

标签: php mysql


【解决方案1】:

在你的 htaccess 中你放了这样的东西(如果使用 apache)

RewriteEngine On

#ignores real files
RewriteCond %{REQUEST_FILENAME} !-f

#ignores real directorys
RewriteCond %{REQUEST_FILENAME} !-d

#ignores symlinks
RewriteCond %{REQUEST_FILENAME} !-l

#forwards the request onto index.php with the orignal querystring still intact

RewriteRule (.+) index.php?url=$1 [QSA]

那么 / 之后的任何东西都会被转发到 index.php 中的 $_GET['url'] 中。 然后在 index.php 中,你可以有一个引导类,它将 explode this by /。 然后你可以根据这个数组中的第一个元素加载适当的类。

例如,如果 url 是 /articles

它将根据 /articles 加载文章控制器

或者如果网址是 /articles/about-something

articles 控制器将通过从数据库中获取带有 about-something slug 的文章来加载文章。

【讨论】:

  • 为此干杯,我会尝试并让您知道结果接缝,就像我有分配代码要编辑以使其工作一样,值得一试,干杯。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-02-24
  • 1970-01-01
  • 2013-07-30
  • 1970-01-01
  • 2010-11-18
  • 2011-08-31
  • 1970-01-01
相关资源
最近更新 更多