Codeigniter SEO Friendly URL Structure - Mostlikers

13 April, 2016

Codeigniter SEO Friendly URL Structure

URL structure is one of the most important technique to improve SEO. A good URL structure can help in increasing the website traffic volume. There are many websites on the internet that do not have a proper URL structure, especially in case of shopping carts.

Codeigniter SEO Friendly URL Structure

In this post we will be seeing, how to create a proper SEO friendly URL structure using Codeiginter.
It is easy to structure the URL for search engines and human readability as Codeigniter designs the SEO friendly URL without any queries. 

Removing index.php from url

By default the codeigniter URL structure will be You can notice the index.php in the URL which is not user friendly, you can easily remove index.php by using a .htaccess code.

Create a new file in the root folder of  Codeigniter with file name as".htaccess".


Paste the below code in the .htaccess file.

RewriteEngine on
RewriteCond $1! ^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

Now type the URL without the index.php and the URL work's just fine. If it doesn't work then make sure that the value of the  $config['index_page'] is empty in the file config.php in the folder /application/config.

$config['index_page'] = ""

Default controller

When u download the Codeigniter framework the default controller will be welcome controller. To change the default controller, open your application/config/routes.php file and make the below change.

$route['default_controller'] = 'welcome'
change to 
$route['default_controller'] = 'other_controller'

URI Routing 

URI rountimg is the major function in the Codeiginter because it will work with dynamic url, with the help of URI rounting you can write clean url structure. 

Example :

While looking welcome/about doe's not have more SEO friendly. Remove the welcome it will be looking fine. Follow the below steps to clean the urls.

Setting Rounting urls

Routing rules are defined in your application/config/routes.php file. you can see the default_controller class name to this line follow the rules to define the URL structure.

$route['default_controller'] = "welcome";
$route['about'] = "welcome/about";
$route['service'] = "welcome/service";
$route['contact'] = "welcome/contact";

Now remove the controller class name, it will work.

Setting Dynamic URL's Route

A Dynamic URL containing the words and numbers. Routing developed with wildcard You can match literal values or you can use two wildcard types.

(:num) -  will match a segment containing only numbers.
(:any)   - will match a segment containing any character. 

Example :

Incase that id value is static write text with the controller class name
$route['blog/new-topic-list'] = "blog/index/1";
$route['blog/old-topic-list'] = "blog/index/12";

Dynamic Product URL

Store your product URL's to the database pass the specify product url along with the controller class name.

Example category url

rounting code would be

$route['mens-clothing/(:any)']    =   "mens/clothing/$1";

mens - It is a controller class name
mens/clothing/ -It is a controller function name
$1- it is a third url segment value.

Example product urls

rounding code should be

$route['default_controller'] = "product";
$route['(:any)'] = "product/index/$1";

Adding a URL Suffix

Adding a URL Suffix at the end of the your url is a good thing, suffixes like .html, .php. With these extenstion search engines also consider the page as static .

Open file /application/config/, find the $config['url_suffix'] line. Add your extension format and save the file

$config['url_suffix'] = '.html'; it will work with

Related Topics