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 [email protected]
    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>
0

1 Answer 1

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>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.