简体   繁体   中英

SEO friendly Blogs links in CodeIgniter

I am creating a website in CodeIgniter, In blog section the blog link is

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

But i want links like

http://www.example.com/something-something

That i have save in database Please help..

You can use codeigniter url_title method to do so

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

for more : https://www.codeigniter.com/user_guide/helpers/url_helper.html#url_title

You should do following steps for making SEO friendly Blogs links in CodeIgniter

Add following code in /application/config/routes.php

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

Create new controller called Blogs.php in /application/controllers

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

        echo $param;

    }
}
?>

then, change your URL's in view files.

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

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

-OR-

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM