-1

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"
</FilesMatch>

# 1 WEEK
<FilesMatch "\.(jpg|png|gif|css|js)$">
Header set Cache-Control "max-age=604800, public"
</FilesMatch>

# Add correct content-type for fonts 
AddType application/vnd.ms-fontobject .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
</Directory>

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 127.0.1.1 (/etc/apache2/sites-enabled/000-default.conf:1)
         port 80 namevhost 127.0.1.1 (/etc/apache2/sites-enabled/000-default.conf:1)
         port 80 namevhost edmhunters.com (/etc/apache2/sites-enabled/edmhunters.com.conf:1)
                 alias www.edmhunters.com
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/apache2.pid"
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
User: name="www-data" id=33
Group: name="www-data" id=33

What did I miss here?

user
  • 4,335
  • 4
  • 34
  • 71
Yin Yang
  • 273
  • 3
  • 12
  • If you have write access to the virtualhost config file, put the `.htaccess` content in there and set `AllowOverride` to `None`, as this removes the need for apache to scan the whole directory tree above each request for `.htaccess` files. Read: performance is negatively influenced by using `.htaccess` files. – Phillip -Zyan K Lee- Stockmann Oct 07 '18 at 07:57

1 Answers1

-1

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.

Yin Yang
  • 273
  • 3
  • 12