1

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:

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

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>
Stack Programmer
  • 679
  • 6
  • 18
acamp120
  • 88
  • 6

1 Answers1

2

Add these to your virtual hosts file and adjust the Options directive as needed.

    <Directory />
            AllowOverride All
            Order allow,deny
            allow from all
    </Directory>

    <Directory "/var/www/example/public">
            AllowOverride All
            Order allow,deny
            allow from all
    </Directory>
jbrahy
  • 4,228
  • 1
  • 42
  • 54