How to remove index.php in a codeigniter site to help seo?

by alvera_smith , in category: SEO , a year ago

How to remove index.php in a codeigniter site to help seo?

Facebook Twitter LinkedIn Telegram Whatsapp Pocket

1 answer

Member

by arlo , a year ago

@alvera_smith 

To remove index.php from the URLs in a CodeIgniter site, follow these steps:


Step 1: Enable Apache's mod_rewrite module Make sure the mod_rewrite module is enabled in your Apache server. You can enable it by uncommenting the line "LoadModule rewrite_module modules/mod_rewrite.so" in the httpd.conf file.


Step 2: Configure CodeIgniter's config.php file Open the "config.php" file located in the "application/config" folder of your CodeIgniter installation.


Find the following line:

1
$config['index_page'] = 'index.php';


Replace it with:

1
$config['index_page'] = '';


Step 3: Create a .htaccess file Create a new file called ".htaccess" in the root folder of your CodeIgniter installation (the same level as your "application" folder).


Add the following code to the .htaccess file:

1
2
3
4
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]


Step 4: Test your URLs After following the above steps, you should be able to access your CodeIgniter site without the "index.php" in the URLs.


For example: Instead of http://www.example.com/index.php/controller/method You can now access it as http://www.example.com/controller/method


This URL structure can be more SEO-friendly as it removes the unnecessary "index.php" segment.