I have url like this :
http://domain/sentencijos/autoriai/429/marselis-prustas
,
where sentencijos is a controller, autoriai is a method, 429(param)
is marselis prustas ID. I want to remove this param (ID) but don't know how.
Full url should look like this:
http://domain/sentencijos/autoriai/marselis-prustas
Can someone help me? Thanks
Replace
slug
withid
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 neitherSEO friendly
norUser friendly
. Below is the example of an URL usingproduct id
,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 usingproduct slug
,Here,
apple-iphone-5S-16GB-brand-new
is a slug.You can also understand from the URL of this page,
where,
24800780 = this is the unique
question_id
how-to-remove-params-from-url-codeigniter = this is the
slug
made from yourquestion
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.In your code:
Assuming this to be your URL,
and this
marselis-prustas
might be yourslug 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 otherslugs
.Advantages of slug in URLs:
1) SEO Friendly
2) User Friendly
3) Clean and semantic URLs