I am attempting to remove the index.php from my CodeIgniter 3 URLs. Currently, all of my URLs look like this:
http://example.com/index.php/Controller/function
And I want them to look like this:
http://example.com/Controller/function
I have followed along on the following article and Stack Overflow post, yet none of the answers I've found have worked for me:
- https://www.codeigniter.com/userguide3/general/urls.html
- How to remove "index.php" in codeigniter's path
My directory structure is set up as follows:
- /var/www/example
- /application
- (standard CodeIgniter application files... controllers, models, views, configs)
- /public
- /css
- /js
- /fonts
- /images
- index.php
- .htaccess
- /system
- I haven't touched anything in this directory
- .htaccess
- /application
Contents of /var/www/example/.htaccess:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ public/ [L]
RewriteRule (.*) public/$1 [L]
</IfModule>
Contents of /var/www/example/public/.htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [QSA,L]
</IfModule>
Contents of /var/www/example/application/config/config.php (trimmed to what I've changed based on prior reading):
$config['base_url'] = '';
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI'; /* have tried AUTO as well */
For my Apache server, mod-rewrite has been enabled via:
sudo a2enmod rewrite
sudo service apache2 restart
My virtual host file for this site is:
<VirtualHost *:80>
ServerAdmin myemail@example.com
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/example/public
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>