I have url like this :
http://domain/sentencijos/autoriai/429/marselis-prustas
,
where sentencijos is a controller,
Replace slug
with id
in your URLs.
This is how it works:
1) I'm assuming here a product website flow.
2) For a particular product page, displaying the product details need some data from the URL (it can be anything product id
, product slug
, etc).
3) Using product ids
in URLs is not considered a good practice. Its neither SEO friendly
nor User friendly
. Below is the example of an URL using product id
,
http://www.example.com/products/123/
4) Hence, an alternative to this is what is called as product slug
5) A slug (semantic URL or Permalinks)
is basically a meaningful, seo friendly, human readable sequence of keywords separated by hyphens (or underscores). Below is the example of an URL using product slug
,
http://www.example.com/products/apple-iphone-5S-16GB-brand-new/
Here, apple-iphone-5S-16GB-brand-new
is a slug.
You can also understand from the URL of this page,
http://stackoverflow.com/questions/24800780/how-to-remove-params-from-url-codeigniter
where,
24800780 = this is the unique question_id
how-to-remove-params-from-url-codeigniter = this is the slug
made from your question
How to use slug?
1) Ofcourse your 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.
id | title | slug | price | thumbnail | description
In your code:
Assuming this to be your URL,
http://domain/sentencijos/autoriai/marselis-prustas
and this marselis-prustas
might be your slug value
which your controller function will receive and pass to the model which gradually use this to query the database.
For this, you have to create a new column (as explained above) which should have the value marselis-prustas
and also other slugs
.
Advantages of slug in URLs:
1) SEO Friendly
2) User Friendly
3) Clean and semantic URLs