.htaccess Tutorial
. htaccess is a configuration file for use on web servers running the Apache Web Server software.

What is the .htaccess
.htaccess is a configuration file for use on web servers running the Apache Web Server software. When a .htaccess file is placed in a directory which is in turn 'loaded via the Apache Web Server', then the .htaccess file is detected and executed by the Apache Web Server software. These .htaccess files can be used to alter the configuration of the Apache Web Server software to enable/disable additional functionality and features that the Apache Web Server software has to offer. These facilities include basic redirect functionality, Error Document, file protect and many more ..
Where Is the .htaccess
File?
.htaccess file location is most commonly found in your website's public_html folder.
Why Can’t I Find My .htaccess
File?
There are two common reasons for not finding the .htaccess file in your website’s root folder. It’s either hidden by your file manager software, or it doesn’t exist at all.
How to Change Path or overwrite
DirectoryIndex index.html
ErrorDocument
ErrorDocument 500 "Sorry, our script crashed. Oh dear"
ErrorDocument 500 /cgi-bin/crash-recover
ErrorDocument 500 http://error.example.com/server_error.html
ErrorDocument 404 /htaccess/errors/error_404.html
ErrorDocument 401 /subscription/how_to_subscribe.html
Enable or Disable Directory
If we xyz.html indexing file then our directory is showing so its important to hide
Options -Indexes
Options +Indexes
hide file directory browsing
suppose we protect some extension file like jpg , pdf that time we can use
IndexIgnore *.pdf *.jpg*png
Suppose use IndexIgnore *
Enable or Disable Directory is work but that time does not work 404 error
Block access specific website
RewriteEngine On
RewriteCond %{HTTP_REFERER} youtube\.com [NC]
RewriteRule .* - [F]
Remove Index.php file
You can use the htaccess file framework like coordinator, Laravel
RewriteEngine on
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
#RewriteRule .* index.php/$0 [PT,L]
Remove .html/.php Extension
Options +MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.html [NC,L]
Leverage browser caching
ExpiresActive On
ExpiresDefault "access plus 1 year"
ExpiresByType text/html "access plus 1 seconds"
ExpiresByType image/gif "access plus 1 year"
ExpiresByType image/jpeg "access plus 1 month"
ExpiresByType image/png "access plus 2592000 seconds"
ExpiresByType text/css "access plus 604800 seconds"
ExpiresByType text/javascript "access plus 216000 seconds"
ExpiresByType application/x-javascript "access plus 216000 seconds"