How to Enable and Configure Seo-friendly Urls in Codeigniter?

2 minutes read

Creating SEO-friendly URLs is essential for the visibility of your website. In CodeIgniter, you can achieve this by removing the index.php from the URL and configuring your site accordingly. In this article, we will guide you through enabling and configuring SEO-friendly URLs in CodeIgniter.

Why SEO-Friendly URLs?

SEO-friendly URLs are crucial because they help search engines index your content more effectively. Clean URLs improve the user experience, making your content more accessible to visitors. Removing unnecessary parts of the URL, like index.php, creates a more meaningful and readable URL structure.

Step-by-Step Guide to Enable SEO-Friendly URLs in CodeIgniter

Step 1: Remove index.php from URLs

To remove index.php from your URLs, you need to modify your .htaccess file. This file uses Apache’s rewrite module to direct requests appropriately.

  1. Create or Edit the .htaccess File:

At the root of your CodeIgniter application (where your index.php file is located), create or edit a file named .htaccess with the following content:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
   RewriteEngine On
   RewriteBase /

   # Redirect to remove index.php
   RewriteCond %{REQUEST_URI} ^system.*
   RewriteRule ^(.*)$ /index.php?/$1 [L]

   RewriteCond %{REQUEST_URI} ^application.*
   RewriteRule ^(.*)$ /index.php?/$1 [L]

   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteCond %{REQUEST_FILENAME} !-d
   RewriteRule ^(.*)$ index.php?/$1 [L]
  1. Enable mod_rewrite:

Ensure that the mod_rewrite module is enabled in your Apache server. You can do this by running the following command:

1
2
   sudo a2enmod rewrite
   sudo service apache2 restart
  1. Edit Configuration:

Open application/config/config.php and modify the following line to remove index.php:

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

Set the uri_protocol to:

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

Step 2: Use SEO Plugins for Additional Optimization

To further enhance your SEO efforts, consider using plugins that automate SEO tasks in CodeIgniter. You can find plugins to help with metadata, sitemaps, and more. Here are some resources to get you started:

Step 3: Test and Verify

After making these changes, test your URLs to ensure they’re working as expected. Access various parts of your site to confirm that the URLs are clean and functional.

Useful Resources

By following the steps outlined above, you can successfully enable and configure SEO-friendly URLs in your CodeIgniter application. This will ensure that your web application is better optimized for search engines, enhancing its visibility and user engagement.

Facebook Twitter LinkedIn Telegram Whatsapp

Related Posts:

In 2025, search engine optimization (SEO) continues to be a critical aspect for enhancing the visibility of your website. For WordPress users, optimizing the homepage can significantly impact your site’s overall performance in search engine rankings. Here’s ho...
If you’re planning to use CodeIgniter for your web development needs, optimizing your setup and configuration for maximum performance is crucial. With a well-configured CodeIgniter project, you can ensure faster load times, improved scalability, and a smoother...
To launch CodeIgniter on Hostinger, follow these steps:Sign in to your Hostinger account and go to the control panel.Scroll down to the "Website" section and select "Auto Installer".In the search bar, type "CodeIgniter" and select it fr...