.htaccess file ignored on Ubuntu server
Solution 1:
I worked out what it was since I opened this thread: there were two issues that I would have thought would crop up in any vanilla LAMP setup installed according to the Media Temple Knowledgebase article (which was what I used to set up the (ve) server).
Firstly, it was the rewrite module. It appeared as though my .htaccess
files weren’t being read by the server because a rewrite module has to be enabled: this seems to be the default on a fresh install such as the one I just carried out. Who knew?
Enabling the module is pretty simple: I just needed to make a symbolic link to the rewrite.load
file from the mods-available directory to the mods-enabled directory (all found, in this instance, in the apache2 directory, at /etc/apache2
).
Ran the following:
cd /etc/apache2/mods-enabled
ln -s /etc/apache2/mods-available/rewrite.load rewrite.load
Secondly, I concluded I also need to change all instances of AllowOverride
in /etc/apache2/sites-available/default
(which are all set to None
by default) to All
(see this article which explains the issue).
Finally was the question of how to apply the rules. I actually chose to delete my .htaccess file and place all its rules in a <Directory>
section in http.conf
(which is now a separate file still called in apache2.conf, and which I'll use to include all my customizations), because setting AllowOverride
to None
and relying on apache2.conf
for everything induces an increase in speed as the server no longer has to check for an .htaccess
file at every level before loading a page. I then deleted the .htaccess
, set AllowOverride
to None
, and the rules still loaded fine.
Solution 2:
This sounds like mod_rewrite isn't enabled. Try running the following:
a2enmod rewrite
If the command reports back that rewrite has been enabled, restart Apache with sudo service apache2 restart
if it says that it's already enabled, then this isn't the answer :)
Solution 3:
Ensure the following:
/etc/apache2/apache2.conf
#
# AccessFileName: The name of the file to look for in each directory
# for additional configuration directives. See also the AllowOverride
# directive.
#
AccessFileName .htaccess
#
# The following lines prevent .htaccess and .htpasswd files from being
# viewed by Web clients.
#
<Files ~ "^\.ht">
Order allow,deny
Deny from all
Satisfy all
</Files>
Ubuntu - HTTPD - Apache2 Web Server might be of help.
--edit--
-
Changes to .conf files do not take effect immediately, a restart will always be required. A reload might also work, but I'm not sure in which situations a reload just isn't enough.
/etc/init.d/apache2 restart