I'm trying to enable use of htaccess file in Ubuntu 14.04 (Apache 2.4.7). I know that this question has many possible duplicates, but none of them helped me yet.


ErrorDocument 404 /404.html


<VirtualHost *:80>
AccessFileName .htaccess

ServerAdmin webmaster@localhost
DocumentRoot /var/www

ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

<Directory /var/www/>
  Options Indexes FollowSymLinks Includes
  AllowOverride All
  Order allow,deny
  Allow from all

What else is needed?

  • 1
    The AllowOverride All directive allows all options in the .htaccess file. The 000-default.conf assumes that there is only one site on your server. Is the .htaccess file not working for you? Are there more than one site hosted on this server?
    – closetnoc
    Apr 23 '14 at 18:40
  • There are many folders in /var/www but no virtual hosts are created. /etc/apache2/sites-available/ folder contains two files, 000-default.conf and default-ssl.conf. htaccess file is located in /var/www/
    – David ZIP
    Apr 23 '14 at 20:27
  • Maybe 'DocumentRoot /var/www/'? (trailing slash) Apr 23 '14 at 21:08
  • Check to make sure /etc/apache2/sites-enabled/ contains a link to 000-default.conf. If you change the /var/www/index.html file you can see the changes when you view the server with a web browser, right? Apr 24 '14 at 1:52

First Step

Open file as

sudo vim /etc/apache2/apache2.conf

Second Step

remove comment sign (#) if you find it before this line ( line number 187 approx.)

AccessFileName .htaccess

Third Step

Then find the line where there is

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

replace "None" with "All"

AllowOverride All

And voila... .htaccess works!!

  • 3
    changes didn't take effect until I restarted apache Command: service apache restart Feb 3 '15 at 15:59
  • 1
    I suggest, as @TahirYasin mentions, restarting apache. sudo service apache2 restart.
    – www139
    Dec 23 '16 at 4:55

Activate ModRewrite:

sudo a2enmod rewrite
sudo /etc/init.d/apache2 restart
  • 1
    The service command is now the preferred way to restart Apache: sudo service apache2 restart. Sep 12 '14 at 8:36

In my case the changing AllowOverride None to AllowOverride All in /etc/apache2/sites-enabled/000-default.conf helped.

All other .conf files have already had AllowOverride All.

  1. In /etc/apache2/apache2.conf remove comment sign (#) from AccessFileName .htaccess
  2. The name of your Apache configuration file is not standard. You can rename it to default.conf in Windows and rename it to default in Linux. In Linux based OS run this code in terminal:

    sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/default
  • It is named with the zeros so that it comes first alphabetically. If you have a default.conf file and then create a site for anteater.com, then anteater becomes the default host because it gets loaded first. Keep the 000 to prevent such problems. The name of the conf file shouldn't have anything to do with whether or not .htaccess works. Apr 24 '14 at 1:50
  • 1
    'AccessFileName .htaccess' is already uncommented. Above answer helped me. Thanks.
    – David ZIP
    Apr 25 '14 at 5:16

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.