I recently set up a client website on Bluehost shared web hosting and found that a few tweaks were needed to the .htaccess file for better website performance (reduced page load time) and security. A .htaccess file is a simple text file that you can place in any web project root directory to make web server configuration changes.
I figured I’d document the changes I made here for next time and in case it helps anyone else that’s getting set up on Bluehost.
- I added
Options +Multiviewsso that .php file extensions on the website would be hidden. For example, a URL of http://example.com/foo would mean the web server would know to look for http://example.com/foo.php and serve that page. This lets you use clean, SEO-friendly URLs.
- I added
so that gzip compression would be enabled for the site. This is something that should definitely be enabled if your web host allows it, as it greatly helps reduce page weight and decreases page load time. For more information on page compression, see the Google PageSpeed site article on this. If you’re curious exactly how gzip compression works on a site, see the Google Developers site’s gzip compression video.
- I added
Options -Indexesto disable directory browsing on the site. Since this .htaccess file was placed in the website root directory, this disables directory browsing in that directory and all sub-directories. This is a good idea for security reasons (so people can’t snoop around in the sub-directories of a website). Without this setting, a index.html or index.php file will be shown, if present, and if one isn’t found, an entire directory listing (with links to each file) will be shown.
These tweaks left me with the following .htaccess file:
# Use PHP5.4 as default AddHandler application/x-httpd-php54 .php # Hide PHP file extension Options +Multiviews # Enable gzip for compression <ifmodule mod_deflate.c> # Disable directory browsing Options -Indexes