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.
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 www.yourwebsite.com/index.php/any_other_page/. 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 onRewriteCond $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
Example :
example.com/welcome/about
example.com/welcome/service
example.com/welcome/contact
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 example.com/about, 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 :
example.com/blog/index/1
example.com/blog/index/12
example.com/product/index/2
example.com/news/index/3
$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
example.com/mens-clothing/t-shirt/
example.com/mens-clothing/shirt/
example.com/mens-clothing/trousers/
$route' [ -clothing/( mens any)'] = " : /clothing/$1"; mens
$1- it is a third url segment value.
Example product urls
example.com/mens-fit-shirt-sale/
example.com/woman-fit-shirt-sale/
example.com/kids-fit-shirt-sale/
$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/config. ph , find the $config[ 'url_suffix'] line. Add your extension format and save the file
$config'url_suffix'] = ' [ html'; .
example.com/product/men-shirts it will work with example.com/product/men-shirts.html
Related Topics
- Email With Customized HTML Template Using Codeigniter
- Display Flash Message In CodeIgniter
- Session In Codeigniter
- Ajax Login System In Codeigniter
- CodeIgniter Remove Index.Php In URL
- Login With Facebook Using Codeigniter
- CodeIgniter My Model tutorial
- Codeigniter Load CSS And Javascript Files
- Convert Html To Codeigniter And Basic Steps Of Codeigniter
Thank you, i was looking for the same ... finally i got it ...
ReplyDeleteWelcome
DeleteThanks....
ReplyDeleteThis comment has been removed by a blog administrator.
ReplyDelete