I'm having a problem with an .htaccess file on a newly installed Ubuntu server running Apache2.

The .htaccess file in the directory where the WordPress files are located isn't being take into account when the server loads pages. There isn't an AllowOverride statement in the apache2.conf file, but the default is All, and it doesn't change anything if I include one.

I've tried including the contents of the local .htaccess file in a section. I've also tried this:

<Directory /var/www/mydomain.com/html>
AllowOverride All

I also tried changing all instances of AllowOverride in /etc/apache2/sites-available/default (which are all set to Noneby default) to All.

But I've had no luck.

Not sure how to solve this one.

  • The first thing to check is file permissions. Can Apache read your .htaccess file? Dec 10, 2011 at 10:00
  • @Scott Severance: permissions are set to 644. I also posted the question on the Webmasters site: thanks for the suggestion! Dec 10, 2011 at 10:02
  • Make sure that you restart the apache service after modifying the files in /etc/apache2: sudo /etc/init.d/apache2 reload (if this fails, try restart instead of reload)
    – Lekensteyn
    Dec 10, 2011 at 10:17
  • It says apache2 is a directory. But don't changes to .conf files take effect immediately? Rebooting the whole server doesn't do it either… Dec 10, 2011 at 10:28

3 Answers 3


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 AllowOverrideto None, and the rules still loaded fine.

  • It is strongly preferred to use a2enmod and a2dismod for enabling and disabling Apache modules in Ubuntu. Dec 10, 2011 at 19:34
  • You mean instead of the symbolic link? But mod_rewrite was enabled, I checked, and it wouldn't load the rules. Or do you mean the combination of both? Dec 10, 2011 at 19:38
  • If it was enabled and there was a problem with it not being loaded then there is likely something not vanilla with your setup. Dec 10, 2011 at 19:40
  • Ouch! But what exactly's less optimal with the symbolic link? Dec 10, 2011 at 19:42
  • The second point was the key of my locked lock!
    – smhnaji
    Nov 7, 2012 at 16:16

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 :)

  • Thanks! Actually mod_rewrite was already enabled (I checked). But I worked it out (see my answer below). Dec 10, 2011 at 19:22
  • This is equivalent to doing the symbolic link as I suggest in my solution, as it creates it, but is better as the author points out. Dec 11, 2011 at 2:03

Ensure the following:


# 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

Ubuntu - HTTPD - Apache2 Web Server might be of help.


  • 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


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.