Pages

Sunday, September 29, 2013

CodeIgniter-Seo Urls

1. I am using ubuntu 13.04. To setup mod_rewrite on debian based machines ubuntu is in concern here go through my this post

http://itfeast.blogspot.in/2013/09/cakephpubuntu-setting-up-cakephp-on.html

If you are assured that mod_rewrite is working perfectly on your Apache Server Proceed Further.

Now We will proceed with configuring CodeIgniter for seo urls

2. Remove Index.php

Your root .htaccess should look like this

 <IfModule mod_rewrite.c>  
 # Turn on URL rewriting  
 RewriteEngine On  
 # If your website begins from a folder e.g localhost/my_project then   
 # you have to change it to: RewriteBase /my_project/  
 # If your site begins from the root e.g. example.local/ then  
 # let it as it is  
 RewriteBase /ci/  
 # Protect application and system files from being viewed when the index.php is missing  
 RewriteCond $1 ^(application|system|private|logs)  
 # Rewrite to index.php/access_denied/URL  
 RewriteRule ^(.*)$ index.php/access_denied/$1 [PT,L]  
 # Allow these directories and files to be displayed directly:  
 RewriteCond $1 ^(index\.php|robots\.txt|favicon\.ico|public|assets|css|js|images)  
 # No rewriting  
 RewriteRule ^(.*)$ - [PT,L]  
 # Rewrite to index.php/URL  
 RewriteRule ^(.*)$ index.php/$1 [PT,L]  
 </IfModule>  

3. Now in application/config/config.php

change
$config['index_page'] = 'index.php';
to
$config['index_page'] = '';

In some cases you may also need to configure

$config['uri_protocol'] = 'AUTO';

To

$config['uri_protocol'] = 'PATH_INFO';

Or To

$config['uri_protocol'] = 'REQUEST_URI';

4. Now your folder structure should look like this

website_folder/ 
–––– application/ 
–––– system/ 
–––– user_guide/ 
====>.htaccess
–––– index.php 
–––– license.txt
 
You might also go for custom routing further as
 
$route['default_controller'] = 'webpages'; //Our default Controller

//Get rid of the first segment (in our case we get rid of webpages)
$route["about"] = 'webpages/about'; 
$route["blog/(.*)"] = 'webpages/blog/$1';
$route["view/(.*)"] = 'webpages/view/$1';
 
Source: http://www.web-and-development.com/codeigniter-remove-index-php-minimize-url/ 

No comments:

Post a Comment