Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange
The results are in! See what nearly 90,000 developers picked as their most loved, dreaded, and desired coding languages and more in the 2019 Developer Survey.

Directory-level configuration file found mostly on Apache web servers

The .htaccess file is a configuration file for the Apache web server, allowing configuration settings to be made at a directory-specific level, overriding the server-wide or site-level settings in the main Apache config.

Most (though not all) Apache settings can be configured in .htaccess. One of the most common usages for it is URL redirection using mod_rewrite, which is used by many sites for SEO purposes and to provide easier-to-read URLs. The Apache documentation also has further information about mod_rewrite.

.htaccess files can also be used for specifying custom error pages (e.g. for 404 errors); directory-specific security and user authentication; configuring the PHP installation; file handlers and MIME types; output compression, and more.

The htaccess file is used by the mod_rewrite module of the Apache webserver. It allows URLs to be rewritten for scenarios such as the following

  • Shortcuts such as to redirect to another page
  • Redirects from old pages to new pages
  • Password protection of directories and files

For full documentation see the mod_rewrite documentation. For more information on .htaccess files and how to use them, see the Apache documentation.

history | excerpt history