Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

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.

.htaccess: ErrorDocument 404 /404.html

000-default.conf

<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
</Directory>
</VirtualHost>

What else is needed?

share|improve this question
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 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 at 20:27
    
Maybe 'DocumentRoot /var/www/'? (trailing slash) –  Kovah Apr 23 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? –  Stephen Ostermiller Apr 24 at 1:52

4 Answers 4

up vote 3 down vote accepted

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 AllowOverrideNone Require all granted </Directory>
replace "None" with "All"
AllowOverride All

And voila .... htaccess works!!

share|improve this answer
    
Finally! Thank you! –  David ZIP Apr 25 at 5:13

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.

share|improve this answer
  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
    
share|improve this answer
    
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. –  Stephen Ostermiller Apr 24 at 1:50
    
'AccessFileName .htaccess' is already uncommented. Above answer helped me. Thanks. –  David ZIP Apr 25 at 5:16

Activate ModRewrite:

sudo a2enmod rewrite
sudo /etc/init.d/apache2 restart
share|improve this answer
    
The service command is now the preferred way to restart Apache: sudo service apache2 restart. –  Stephen Ostermiller Sep 12 at 8:36

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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