Hypertext Access, know as htaccess, is a configuration file which controls the directory it is placed in and all the subdirectories underneath it. It is used on apache web server to control many features of server. It’s just a small text file that can be edited via notepad or any text editor but make sure never save it as .txt or .htm , Its only name is .htaccess. It can be found in server’s root directory in public_html folder.
Some web host server never allow you to edit htaccess, but you can create your own .htaccess file via any text editor and saved it as .htaccess and place it in your web directory. It will control all subdirectory in it.
Basic use of htaccess –
Htaccess is used for redirection like temporary 302 , 301 permanent redirection. It can be used to redirect error pages for better visitor expierence.
Htaccess files are normally enabled by default. This is actually controlled
by the AllowOverride Directive in the httpd.conf file. With htaccess file we can block specific IP, websites, spam links etc. We can also block search engines to crawl our websites.
How to deny an IP –
deny from 100.100.100.100 #specify a specific address
deny from 184.108.40.206/30 #specify a subnet range
deny from 123.123.* #specify an IP address wildcard
allow from all
How to allow an IP –
#Allow List order allow,deny
allow from 220.127.116.11 #specify a specific address
allow from 18.104.22.168/30 #specify a subnet range
allow from 123.123.* #specify an IP address wildcard
deny from all
How to redirect via .htaccess?