.htaccess (hypertext access) file is an Apache HTTP server configuration file
.htaccess file is mostly used for
- Rewriting URLs
- Controlling cache
- Server-side includes
If you have access to the main server configuration file (usually called
You should add the logic from the
For example, a
<Directory>section in the main configuration file.
This is usually the recommended way, as using
.htaccessfiles slows down Apache!
.htaccess is used for
- Allowing cross-origin access to web fonts
- CORS header for images when browsers request it
404.htmlas 404 error document
- Making the website experience better for IE users better
- Media UTF-8 as character encoding for
- Enabling the rewrite URLs engine
- Forcing or removing the
www.at the beginning of a URL
- It blocks access to directories without a default document
- It blocks access to files that can expose sensitive information.
- It reduces MIME type security risks
- It forces compressing (gzipping)
- It tells the browser whether they should request a specific file from the
server or whether they should grab it from the browser’s cache
.htaccess we recommend reading all inline comments (the rules after
#) in the file once. There is a bunch of optional stuff in it.