How to remove index.php in Codeigniter

How to remove index.php in Codeigniter


Published at - Aug 13, 2021

To remove index.php from codeignter urls we need to follow following steps.

Allow overriding htaccess in Apache Configuration (Command)

sudo nano /etc/apache2/apache2.conf
<Directory /var/www/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
</Directory>
sudo a2enmod rewrite
sudo /etc/init.d/apache2 restart

Change $config[‘index_page’] = “index.php” to $config[‘index_page’] = “” in config.php

Change $config[‘uri_protocol’] =”AUTO” to $config[‘uri_protocol’] = “REQUEST_URI” in config.php

Create .htaccess file in root dir of your application and paste the following code

RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA] 

Reference – https://stackoverflow.com/a/16558169





About author

Harendra
Harendra Kanojiya

Hello, I am Harendra Kumar Kanojiya - Owner of this website and a Fullstack web developer. I have expertise in full-stack web development using Angular, PHP, Node JS, Python, Laravel, Codeigniter and, Other web technologies. I also love to write blogs on the latest web technology to keep me and others updated. Thank you for reading the articles.



Follow Us

Follow us on facebook Click Here

Facebook QR
Scan from mobile
Join our telegram channel Click Here
Telegram QR
Scan from mobile