7

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.

Tjita1
  • 493
  • 2
  • 5
  • 6
  • Do you have `mod_rewrite` installed? `a2enmod rewrite`. – OrangeTux Jan 26 '14 at 14:35
  • Nope. Module mod_rewrite does not exist. How do I solve that then? – Tjita1 Jan 26 '14 at 14:37
  • Yeah, I found that just now, thankyou. How should I write the httpd.conf to get it to work, then? – Tjita1 Jan 26 '14 at 14:39
  • Okay, so a friend of mine, pretty good at this, tells me it wont work if I put it in the httpd.conf, it has to be in a .htaccess to function. Issue is, I got the module running, have removed it from the httpd.conf and made a .htaccess, but it wont work anyways. What now? – Tjita1 Jan 26 '14 at 14:49
  • What is the output of `ls /etc/apache2/sites-enabled` – Dan Jan 27 '14 at 15:52

3 Answers3

11

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
metamorph
  • 1,653
  • 14
  • 14
  • As Chris Gregory reminded, register the new config file, in this case the code-machine.conf (I called it differently so adapt to your conf file): sudo a2ensite code-machine.conf Then: sudo service apache2 restart – firepol Oct 14 '16 at 12:33
2

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
Seth
  • 57,282
  • 43
  • 144
  • 200
2

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