CodeIgniter .htaccess Generator

Remove index.php and enable clean URLs in CodeIgniter.

Version Check!
This generator works for both CodeIgniter 3 (root folder) and CodeIgniter 4 (public folder). Check your version before uploading.

Clean URL .htaccess for CodeIgniter

RewriteEngine On RewriteBase / # Remove index.php from URL RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php/$1 [L] # Security: Disable directory listing Options -Indexes # Security: Protect system and application folders (CI3) RedirectMatch 403 ^/(system|application)/ # Security: Protect env and composer files <FilesMatch "^\.env|composer\.(json|lock)$"> Order allow,deny Deny from all </FilesMatch>

Why CodeIgniter needs a .htaccess?

By default, CodeIgniter requires index.php to be present in all your URLs (e.g., example.com/index.php/welcome). The .htaccess file uses Apache's rewrite engine to hide it, giving you professional-looking URLs like example.com/welcome.

Who should use this?

Developers who want to remove index.php from their URLs and secure their framework folders from direct access.

When NOT to use this?

If you have already configured uri_protocol in your config.php to something that doesn't support query strings or if you are using Nginx.

Plain-English Explanation

RewriteRule ^(.*)$ index.php/$1
Framework Critical

The "Magic" line. It takes whatever you typed in the URL and quietly sends it to index.php so CodeIgniter can process it.

RedirectMatch 403 ^/(system|application)/
Security Recommended

Tells the server: "If someone tries to browse the system or application folders directly, show them a 403 Forbidden error."

RewriteBase /
Compatibility

Ensures the rewrite rules start from the root of your domain. Helpful on some shared hosting environments.

Frequently Asked Questions (FAQs)

For CodeIgniter 3, place the .htaccess file in the same directory as index.php (the project root). For CodeIgniter 4, it should be placed inside the /public folder.
In addition to the .htaccess rules, you must update your CodeIgniter configuration. For CodeIgniter 3, set $config['index_page'] = ''; inside application/config/config.php. This allows clean URLs without index.php.
Yes. Ensure your base_url is set correctly in the configuration file. Also verify that your controllers and routes are correctly defined, as rewrite rules alone cannot fix routing misconfigurations.
  • Forgetting RewriteBase: If your site runs inside a subfolder (for example, example.com/blog/), you must set RewriteBase /blog/.
  • AllowOverride disabled: If your hosting provider does not allow .htaccess overrides, rewrite rules will be ignored entirely.
  • Case sensitivity issues: On Linux servers, Index.php and index.php are different. Always use lowercase file names.
Yes, in most cases. Shared hosting usually supports basic .htaccess rules. If clean URLs do not work, contact your hosting provider to confirm that mod_rewrite and AllowOverride are enabled.