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
. code. htaccess
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. [
'index_page'] = "" [
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.
'default_controller'] = 'welcome'; [
'default_controller'] = 'other_controller' [
Setting Rounting urls
Routing rules are defined in your application/config/routes.php file.
can see the default_controller class name you to this line follow the rules to define the URL structure.
'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.
: ) - will match a segment containing only numbers. num
any) - will match a segment containing any character. :
'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
' [ -clothing/( mens any)'] = " : /clothing/$1"; mens
$1- it is a third url segment value.
Example product urls
'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, . With these php. search engines also consider the page as static extenstion .
Open file /application/config/config
. ph, find the $config 'url_suffix'] line. Add your extension format and save the file [
'url_suffix'] = ' [ html'; .
example.com/product/men-shirts it will work with example.com/product/men-shirts.html
- 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
- Convert Html To Codeigniter And Basic Steps Of Codeigniter