skip to Main Content

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..

2

Answers


  1. 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

    Login or Signup to reply.
  2. 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
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search