.htaccess not being loaded in Ubuntu 14.04 (Apache 2.4.7)

  • Posted September 12, 2014

I’m trying to use the .htaccess file in Ubuntu 14.04 (Apache 2.4.7).

Here is what my .htaccess looks like

    # 1 YEAR
    <FilesMatch "\.(ico|svg|woff|eot|ttf)$">
    Header set Cache-Control "max-age=31536000, public"
    # 1 WEEK
    <FilesMatch "\.(jpg|png|gif|css|js)$">
    Header set Cache-Control "max-age=604800, public"
    # Add correct content-type for fonts 
    AddType application/ .eot
    AddType font/ttf .ttf
    AddType font/otf .otf
    AddType font/x-woff .woff
    AddType image/svg+xml .svg
    # Compress compressible fonts
    AddOutputFilterByType DEFLATE font/ttf font/otf image/svg+xml

I enabled mod_rewrite using a2enmod rewrite

Then I edited /etc/apache2/apache2.conf as follows

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

    AccessFileName .htaccess

However the .htaccess file is still not being loaded. If I add gibberish to the .htaccess file everything still works fine. The .htaccess is located in /var/www/.

Here is the output of apache2ctl -S

  VirtualHost configuration:
   *:80                   is a NameVirtualHost
            default server (/etc/apache2/sites-enabled/000-default.conf:1)
            port 80 namevhost (/etc/apache2/sites-enabled/000-default.conf:1)
            port 80 namevhost (/etc/apache2/sites-enabled/
   ServerRoot: "/etc/apache2"
   Main DocumentRoot: "/var/www"
   Main ErrorLog: "/var/log/apache2/error.log"
   Mutex default: dir="/var/lock/apache2" mechanism=fcntl
   Mutex watchdog-callback: using_defaults
   Mutex rewrite-map: using_defaults
   PidFile: "/var/run/apache2/"
   Define: DUMP_VHOSTS
   Define: DUMP_RUN_CFG
   User: name="www-data" id=33
   Group: name="www-data" id=33

What did I miss here?


have you checked permissions on the .htaccess to make sure www-data can use it? Check your site.config file to make sure it does not have AllowOveride None?

Put this in your .htaccess and if your site redirects from to then .htaccess is working:

#redirect www to website root
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

I have created my own directory like /home/mydirectory/public_html and i upload the .htaccess in the public_html directory. I am trying to load but it does not work as i required even i had changed in apache2.conf file

The isssue was that I was placing the .htaccess file in /var/www/ while my DocumentRoot for my website was pointing to a different directory. Moving the .htaccess file to that folder solved the issue.