HTACCESS file

HTACCESS file
« Back to Glossary Index

An htaccess file (short for Hypertext Access) is a server configuration file used on Apache web servers that allows website owners and developers to control and customise how the server handles requests at a directory level, without needing access to the main server configuration. The file sits within the root directory of a website, or within specific subdirectories, and its instructions apply to that directory and everything within it.

The “.” at the beginning of the filename indicates that it is a hidden file on Unix-based systems, meaning it will not be visible in a standard file directory listing unless hidden files are explicitly shown.

Because .htaccess files allow configuration changes at the website level rather than the server level, they are widely used in shared hosting environments where website owners do not have direct access to the main server settings. Changes made to an .htaccess file take effect immediately, without needing to restart the server.

A htaccess file may be used for any of the following reasons:

  • Implementing redirects — setting up 301 redirects or 302 redirects to forward users and search engines from old URLs to new ones
  • Rewriting URLs — converting dynamic, parameter-heavy URLs into cleaner, more readable static URLs
  • Blocking access — restricting access to specific directories, files, or IP addresses
  • Forcing HTTPS — redirecting all HTTP traffic to the secure HTTPS version of a site
  • Setting custom error pages — defining bespoke pages to display when errors such as 404 or 500 occur
  • Controlling caching — setting browser caching rules to improve page load speed
  • Protecting sensitive files — preventing direct access to files such as configuration files or wp-config.php on WordPress sites
  • Hotlink protection — preventing other websites from directly linking to and serving your images, which can consume your bandwidth

A basic example of a 301 redirect in an .htaccess file looks like this:

Redirect 301 /old-page/ https://www.example.com/new-page/

The .htaccess file is a powerful tool for SEO, particularly for managing redirects, enforcing HTTPS, and cleaning up URL structures. Implementing redirects correctly via .htaccess ensures that link equity is preserved when URLs change and that users are seamlessly directed to the right destination. Forcing HTTPS at the server level via .htaccess is also a straightforward way to ensure all traffic is served securely, which is a confirmed Google ranking signal.

Since .htaccess files are powerful and errors can have significant consequences (including taking a site offline or causing redirect loops), it is important to proceed carefully, always keep a backup of the existing file before making changes, and test thoroughly after any modifications.

« Back to Glossary Index
Facebook
Twitter
LinkedIn

Subscribe To Tech SEO Tips Newsletter

The latest news from the SEO industry, plus tips and discussions on improving your tech SEO performance.