Jasdeep Khalsa
Jasdeep Khalsa

Reputation: 6949

How to get .htaccess files working with Apache VirtualHost

My problem is that my .htaccess file on my local server is not being read. The settings in the VirtualHost file seem to always take precedence.

I have tried the following:

I am using a VirtualHost file on Ubuntu which looks like the following:

<VirtualHost *:80>
ServerAdmin webmaster@localhost

DocumentRoot /web/website
<Directory />
    Options FollowSymLinks
    AllowOverride None
</Directory>
<Directory /web/website>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride None
    Order allow,deny
    allow from all
</Directory>
</VirtualHost>

In my .htaccess file under /web/website I have the following rules (which are not being read):

RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^(.*)$ index.php?/$1 [L]
RewriteCond %{HTTP_USER_AGENT} ^facebookexternalhit
RewriteRule ^(.*)$ ogtags.php?$1 [L,QSA]
ErrorDocument 404 /404
ErrorDocument 401 /401

One thing I tried which did work was appending these rules directly into the VirtualHost file, but I would like my .htaccess file to work! Is that such a big ask? :(

Edit: So I looked in my apache error.log and it says Invalid command 'Action', perhaps misspelled or defined by a module not included in the server configuration referring to my .htaccess file. There doesn't seem to be a module called Action which I can enable. Any ideas?

Edit 2: I noticed that my httpd.conf file is blank. Should this matter since I am using VirtualHost files?

Upvotes: 11

Views: 37876

Answers (2)

Jasdeep Khalsa
Jasdeep Khalsa

Reputation: 6949

After looking at my apache error.log I realised I just had to enable the Apache actions module:

sudo a2enmod actions

And no more 500 Internal Server Errors!

Hope this helps somebody down the line :)

Upvotes: 6

cyberhicham
cyberhicham

Reputation: 493

You miss the RewriteBase / directive

Add it after the RewriteEngine directive :

RewriteEngine On
RewriteBase /

Upvotes: 1

Related Questions