codeigniter seo friendly urls

Codeigniter SEO Friendly URLs

These day’s every website owners concentrate on easy navigation, SEO friendly pages in their websites. It will make their website to engage users. For the time being SEO friendly URLs are going to focus on that part. Codeigniter SEO friendly URLs because it drives more traffic to your site. In this article we are going to make some fun with CodeIgniter URL ReWriting using PHP to build SEO friendly URL’s .

Mostly we do URL rewriting by defining some .htaccess rules but codeigniter gives a more appropriate and easy way to do URL rewriting. We will elaborate it by leads example.

Codeigniter SEO Friendly URLs

As you know that CodeIgniter framework uses a segment-based approach . Let’s take a look on Codeigniter sample URL.

Understand the URL Segments:

domain-name will be your domain name.controller It will be your controller name like in our below example leadControler . method will be function which is associated with controller and next all segments are parameters of function.

Codeigniter URL rewriting configurations by leads example

We are going to make URL’s for list leads , add lead , update lead , view and delete lead. In our example we are going to use for local environment so we are using localhost. If you are going to make it on live server you can place your domain name instead of localhost.
Suppose you have :

Normally URLs will be :

But you want that URLs should be:

You do not need to add HTAccess rules for CodeIgniter url rewriting.Just go to /application/config/routes.php
Approximately line 42 add following lines:

That’s All. Now you can update your hyperlinks and rewrite rules are done.Let’s open link http://localhost/add-lead/
and it will point to http://localhost/leads/add_lead/
Feel free to ask questions just leave us a comment and we will get back to you.
Here is some other articles related to Codeigniter
Install and Setup Codeigniter
CodeigniterRemove index.php from URL