Basically, .htaccess (hypertext access) is configuration file for Apache Web Server or web server which are running on Apache. It’s being used for global configuration changes as per directory basis and configuration in .htaccess file will affect everything in its directory and sub-directories.

Here is the list of some uses of htaccess file

  • URL Rewrite & Redirection
  • Password protection with HTTP Authentication
  • Setting error pages for error like 400 (bad request), 401 (authentication required), 403 (access forbidden), 404 (page not found), 405 (disallowed method), 406 (encoding error), 500 (internal server error) etc
  • Allow access or deny visitors with IP
  • Setting directory index file
  • Enabling gzip compression
  • Force redirect from non-www to www URL and non-http to https URL
  • Adding mime types
  • Disallow directory listing
  • Enabling SSI (Server Side Includes)

and many more other uses ...

We work on several CMS like Craft CMS, ExpressionEngine, WordPress, Statamic etc in which htaccess file comes with URL rewrite. We use it for following performance:

Leverage browser caching for image, Video, JS, CSS and other files

<ifmodule mod_expires.c="">	ExpiresActive On	ExpiresByType image/jpg "access 1 year"	ExpiresByType image/jpe "access 1 year"	ExpiresByType image/jpeg "access 1 year"	ExpiresByType image/tiff "access 1 year"	ExpiresByType image/x-rgb "access 1 year"	ExpiresByType image/x-xbitmap "access 1 year"	ExpiresByType image/gif "access 1 year"	ExpiresByType image/png "access 1 year"	ExpiresByType image/x-xpixmap "access 1 year"	ExpiresByType image/x-xwindowdump "access 1 year"	ExpiresByType image/x-icon "access 1 year"	ExpiresByType image/pnm "access 1 year"	ExpiresByType image/pbm "access 1 year"	ExpiresByType image/pgm "access 1 year"	ExpiresByType image/ppm "access 1 year"	ExpiresByType text/css "access 1 month"	ExpiresByType text/javascript "access 1 month"	ExpiresByType text/json "access 1 month"	ExpiresByType text/plain "access 1 month"	ExpiresByType text/txt "access 1 month"	ExpiresByType text/richtext "access 1 month"	ExpiresByType text/x-setext "access 1 month"	ExpiresByType video/mp4 "access 1 year"	ExpiresByType video/quicktime "access 1 year"	ExpiresByType video/mpeg "access 1 year"	ExpiresByType video/mpg "access 1 year"	ExpiresByType video/mov "access 1 year"	ExpiresByType video/avi "access 1 year"	ExpiresByType video/movie "access 1 year"	ExpiresByType audio/mp3 "access 1 year"	ExpiresByType audio/wav "access 1 year"	ExpiresByType audio/x-midi "access 1 year"	ExpiresByType application/javascript "access 1 month"	ExpiresByType application/pdf "access 1 month"	ExpiresByType application/net "access 1 month"	ExpiresByType application/hqx "access 1 month"	ExpiresByType application/rtf "access 1 month"	ExpiresByType application/tar "access 1 month"	ExpiresByType application/zip "access 1 month"	ExpiresByType application/x-shockwave-flash "access 1 month"	ExpiresByType application/x-javascript "access 1 month"
</ifmodule>