【问题标题】:SEO friendly Blogs links in CodeIgniterCodeIgniter 中的 SEO 友好博客链接
【发布时间】:2018-10-02 18:14:34
【问题描述】:

我正在 CodeIgniter 中创建一个网站, 在博客部分,博客链接是

http://www.example.com/blogs?id=1

但我想要像

这样的链接
http://www.example.com/something-something

我已经保存在数据库中 请帮忙..

【问题讨论】:

标签: php codeigniter


【解决方案1】:

您应该按照以下步骤在 CodeIgniter 中创建对 SEO 友好的博客链接

在/application/config/routes.php中添加以下代码

$route['blogs/(:any)'] = 'blogs/$1';

在/application/controllers 中创建名为Blogs.php 的新控制器

<?php
class Blogs extends CI_Controller{
    public function __construct(){
        parent::__construct();
    }
    public function index($param){

        echo $param;

    }
}
?>

然后,更改您在视图文件中的 URL。

http://www.example.com/blogs?id=1

http://www.example.com/blogs/1

-或-

http://www.example.com/blogs/name-of-the-post

【讨论】:

  • 感谢老兄的作品。但是想想我们可以创建这样的链接吗example.com/name-of-post 更好
  • 你有 blohgpost id 正确的,所以你可以通过id 从数据库中加载博客。然后在此函数中传递博客标题名称url_title($title),它将给出name-of-the-post
【解决方案2】:

您可以使用 codeigniter url_title 方法这样做

$title = "this is my title?";
$url_title = url_title($title);
// Produces: this-is-my-title

更多:https://www.codeigniter.com/user_guide/helpers/url_helper.html#url_title

【讨论】:

    猜你喜欢
    • 2012-04-27
    • 1970-01-01
    • 2015-08-13
    • 2016-05-28
    • 2010-11-01
    • 2013-09-17
    • 1970-01-01
    • 2012-09-17
    • 2014-03-25
    相关资源
    最近更新 更多