mod_rewrite use in Apache 2.4

Okay, so there are plenty of threads on how to use mod_rewrite, but I find it seems to work a bit differently in Apache 2.4. I tried this:

<Directory /var/www/vhosts/example.com>
<IfModule mod_rewrite>
RewriteEngine On
RewriteBase /var/www/vhosts/example.com
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
</IfModule>
</Directory>

This is situated in /etc/apache2/conf-available/httpd.conf/, and I've runt sudo a2enconf httpd.conf which worked and enabled it, but it doesn't want to work anyways..

I tried it without the Directory bit, I tried calling it mod_rewrite.c which wordpress suggests, but neither of the above seems to work. I also tried it with the Directory tag but without IfModule, which for obvious reasons ended up with Apache not starting.. And yes, I restart Apache between every attempt.

Is there a new trick to this in Apache 2.4 that I don't know if? Any help appreciated.


After enabled mod_rewrite by this command:

sudo a2enmod rewrite

Make file for your httpd configuration in /etc/apache2/sites-available/ so in my Ubuntu the file that I make is /etc/apache2/sites-available/code-machine.conf:

DocumentRoot /var/www
<Directory /var/www/>
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>

Edit: And as reminded by Chris Gregory and firepol, you can register the new configuration file code-machine.conf:

sudo a2ensite code-machine.conf

Then restart your apache:

sudo service apache2 restart

even I was facing a similar issue with Apache 2.4 on 14.04

Please note, the configuration file is now located at /etc/apache2/apache2.conf.

I tried this and it worked out for me.

sudo nano /etc/apache2/apache2.conf

Locate the directive Directory where your root directory is located and set the following:

Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All

I had register the new conf file with Apache before it would work.

sudo a2ensite MyConfiguration.conf

Then I could run

sudo service apache2 restart