0

Question: how to make codeigniter dynamic url search engine friendly?

Example: 1

My Current URL: After selecting menu called "Articles"

http://localhost/lw_user/home_control/getMenu/52

Expected URL:

    http://localhost/articles

Example:2 My Current URL: After selecting sub-menu called "thehindu" under menu "articles"

http://localhost/lw_user/home_control/getPage/6

Expected URL:

http://localhost/articles/thehindu

NOTE: This is dynamic URL and contents are fetching from database

ramkumar
  • 1
  • 1
  • 7

2 Answers2

0

What you are talking about is called as slug.

So, how to use slug?

Will explain with an example:
URL - http://www.example.com/products/apple-iphone-5S-16GB-brand-new/

1) Assuming you are having a product page and ofcourse product page needs some data from URL to understand which product to display.
2) Before we were querying our database using the id we are getting from the URL. But now we'll do the same thing (querying our database) just replacing id with slug and thats it!
3) Hence adding an additional column in your database named slug. Below will be your updated product database structure (just an example).

Columns                       Values

id (int(11), PK)              1
title (varchar(1000))         Apple iPhone 5S 16GB
slug (varchar(1000))          apple-iphone-5S-16GB-brand-new
price (varchar(15))           48000
thumbnail (varchar(255))      apple-iphone-5S-16GB-brand-new.jpg
description (text)            blah blah
...
...


I've also answered on slug before. Check if it helps.
How to remove params from url codeigniter
Codeigniter - SEO Friendly URL Structure (Slug Implementation)

Community
  • 1
  • 1
Parag Tyagi
  • 8,780
  • 3
  • 42
  • 47
  • I am getting this below error when running the above code. A PHP Error was encountered Severity: Warning Message: Missing argument 1 for Category::index() Filename: controllers/category.php Line Number: 10 A PHP Error was encountered Severity: Notice Message: Undefined variable: slug Filename: controllers/category.php Line Number: 12 – ramkumar Dec 06 '14 at 12:56
  • What I gave is just an example to explain. You have to run your mind to match it up according to your requirement. – Parag Tyagi Dec 06 '14 at 13:27
0

This has to be done using the routes class.

   $route['product/(:num)'] = "catalog/product_lookup_by_id/$1";

I would suggest you look at the user guide for more info.

https://ellislab.com/codeigniter/user-guide/general/routing.html