PHP routing with Codeigniter (Titles in URL for SEO)

后端 未结 3 987
故里飘歌
故里飘歌 2021-01-15 04:10

I have some questions concering routing with Codeigniter. What I´m doing now is the following:

$route[\'articles/(:num)\'] = \'articles/view/$1\'; // $1 will         


        
3条回答
  •  情书的邮戳
    2021-01-15 04:21

    I suggest you to create a slug field into your table and complete it with the url you want to use as id. Let me explain.

    You have this table

    id
    title
    slug
    

    when you save an article into your db you can dinamically create a slug, for example:

    id: 1
    title: My first post
    slug: 1-my-first-post
    

    then you can use the slug (in this case 1-my-first-post) ad id for the page, you can call it:

    www.example.com/articles/1-my-first-post
    

    obviusly you need to handle it in your db slect

提交回复
热议问题