This might not be directly related to Ubuntu itself, but the directory tree is different here and I'm kind of confused.

I have a website I'm trying to run and it loads fine, but it heavily relies on URL rewrites which I'm not getting because .htaccess directives might not be enabled in my installation. I've followed the article at Ubuntu.com to enable .htaccess files on my apache2, but I couldn't follow it because the files it tells me to change do not exist in the folder it tells me to go.

This is the closest file name to default - 000-default.conf:

<VirtualHost *:80>
    # The ServerName directive sets the request scheme, hostname and port that
    # the server uses to identify itself. This is used when creating
    # redirection URLs. In the context of virtual hosts, the ServerName
    # specifies what hostname must appear in the request's Host: header to
    # match this virtual host. For the default virtual host (this file) this
    # value is not decisive as it is used as a last resort host regardless.
    # However, you must set it for any further virtual host explicitly.
    #ServerName www.example.com

    ServerAdmin webmaster@localhost
    DocumentRoot /var/www

    # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
    # error, crit, alert, emerg.
    # It is also possible to configure the loglevel for particular
    # modules, e.g.
    #LogLevel info ssl:warn

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

    # For most configuration files from conf-available/, which are
    # enabled or disabled at a global level, it is possible to
    # include a line for only one particular virtual host. For example the
    # following line enables the CGI configuration for this host only
    # after it has been globally disabled with "a2disconf".
    #Include conf-available/serve-cgi-bin.conf

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

I don't see any <Directory /var/www/> block here.

How do I enable my .htaccess files? I need them per project basis.


Add to VirtualHost:

<VirtualHost *:80>
   AccessFileName .htaccess (.htaccess is the default filename)
   <Directory /var/www/>
      Options Indexes FollowSymLinks Includes
      AllowOverride All
      Order allow,deny
      Allow from all

then restart apache:

service apache2 restart

To check if it works, add this line to .htaccess :

ErrorDocument 404 /error404.html

for error 404 (page not found) your browse should open your custom error page, in this case error404.html

  • Where exactly is this virtual host? In the file I showed above? And how do I know it started working? – Aborted Apr 9 '14 at 18:39
  • I edited my answer. let me know if it works – girardengo Apr 9 '14 at 20:13
  • Thanks. Unfortunately it's still not working. I get the standard 404 and my script is still not working. You got any alternative to this? – Aborted Apr 9 '14 at 20:32
  • maybe directory path was wrong: i edited. try now. – girardengo Apr 9 '14 at 20:41
sudo -i
sudo nano /etc/apache2/apache2.conf

If your ubuntu 80 port is landing here /var/www/html

(Look carefully it is not /var/www/)

Add this block:

<directory /var/www/html>
     AllowOverride All
  • Welcome to Ask Ubuntu! You may wish to improve your answer by explaining why this would work. – No Time Jul 16 '14 at 19:44

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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