Skip to main content

Directory-level configuration file used by Apache web servers. Use this tag if and only if .htaccess content is directly involved in the topic. We know many people are using .htaccess, but kindly ask the members of the community to not use this tag, unless you know it is on-topic in your question. Also notice what the [tag:apache] tag has to say about questions about _configuring_ Apache httpd and their potential off-topicness on Stack Overflow

The .htaccess (hypertext access) file is a configuration file for the Apache web server, allowing configuration settings to be made at a directory-specific level. It overrides the server-wide or site-level settings in the main Apache server-level configuration but must be enabled in the server-level configuration to work.

Most (though not all) directory-specific 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 has further information about mod_rewrite as well as simpler solutions for many common use cases.

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

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

More information

Top Questions for reference

  1. Tips for debugging .htaccess rewrite rules
  2. Access-Control-Allow-Origin Multiple Origin Domains?
  3. How do I manually create a file with a . (dot) prefix in Windows? For example, .htaccess
  4. How does RewriteBase work in .htaccess
  5. htaccess redirect to https://www
  6. How to redirect all HTTP requests to HTTPS using .htaccess rules?
  7. Hidden features of mod_rewrite
  8. .htaccess redirect all pages to the homepage on a new domain
  9. Create subdomains on the fly with .htaccess (PHP)
  10. .htaccess mod_rewrite - how to exclude directory from rewrite rule
  11. Leverage browser caching for 3rd party JS

How to ask

  • Make sure you explain how .htaccess is involved in your question
  • Explain the expected behavior, the actual behavior and the difference between the two
  • Show the relevant part of the .htaccess