Codeigniter – Apache 2.4.6 default.conf format changed. Unable to run .htaccess

.htaccessApache2codeigniterUbuntu

Guys. I am using codeigniter. I used .htaccess to remove 'index.php' from my url's, and added "Allow from all" to my default.conf. 'index.php' was removed successfully and the site was running. But since the last update of apache, .htacess stopped working and 'index.php' became necessary in the url's. This is my new updated 000-default.conf.

<VirtualHost *:80>
    # The ServerName directive sets the request scheme, hostname and port that
    # the server uses to identify itself. This is used when creating
    # redirection URLs. In the context of virtual hosts, the ServerName
    # specifies what hostname must appear in the request's Host: header to
    # match this virtual host. For the default virtual host (this file) this
    # value is not decisive as it is used as a last resort host regardless.
    # However, you must set it for any further virtual host explicitly.
    #ServerName www.example.com

    ServerAdmin webmaster@localhost
    DocumentRoot /var/www

    # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
    # error, crit, alert, emerg.
    # It is also possible to configure the loglevel for particular
    # modules, e.g.
    #LogLevel info ssl:warn

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    # For most configuration files from conf-available/, which are
    # enabled or disabled at a global level, it is possible to
    # include a line for only one particular virtual host. For example the
    # following line enables the CGI configuration for this host only
    # after it has been globally disabled with "a2disconf".
    #Include conf-available/serve-cgi-bin.conf
</VirtualHost>
#vim: syntax=apache ts=4 sw=4 sts=4 sr noet

I added the following lines to my 000-default.conf, but didn't work:

AllowOverride all
Order allow,deny
Allow from all

My .htaccess is alright because it was working fine before the last update of Apache.

Options -Indexes
RewriteEngine on

RewriteBase /
RewriteCond $1 !^(index\.php|assets|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

RewriteCond %{REQUEST_URI} ^htaccess/ [NC,OR]
RewriteCond %{REQUEST_URI} ^system/function/ [NC,OR]
#just make sure the last rule does  NOT have an OR
RewriteCond %{REQUEST_URI} ^system/class/ [NC]
RewriteRule . - [R=404,L,NC]

My apache version is 2.4.6. Now please tell me what to add to the 000-default.conf to get the .htaccess working and remove 'index.php' from my site url's.

P.S: I am using ubuntu 12.04. mod_rewrite is enabled. I have enabled 000-default.conf i.e. it is available in my sites-enabled folder.

Best Answer

I'm still a new to server/command line land, so I thought I'd append a step by step solution for others in a similar place. Hope this helps someone out:

  1. Login to your server.

  2. Open the 000-default.config file with nano:

    $ sudo nano /etc/apache2/sites-available/000-default.conf
    
  3. Look for this line within VirtualHost: DocumentRoot /var/www/html and add the following just underneath it:

    <Directory /var/www >
        AllowOverride All
    </Directory> 
    
  4. Save your edits: Press CTRL + O to Writeout; then hit RETURN to save your changes

  5. Exit Nano: Press CTRL + X

  6. Restart your server:

    $ sudo service apache2 restart
    
  7. If you need to activate the apache mod_rewrite module, run this command:

    $ sudo a2enmod rewrite 
    

    And if the module is already activated, you'll get a message letting you know all is well.

Related Topic