More .htaccess Examples

Deny/Allow Certain IP Addresses
Block an IP Address

#Deny List

order allow,deny
deny from 198.198.198.198 #specify a specific address
deny from 198.198.198.198/30 #specify a subnet range
deny from 198.198.* #specify an IP address wildcard
allow from all

Allow an IP address

#Allow List

order allow,deny
allow from 198.198.198.198 #specify a specific address
allow from 198.198.198.198/30 #specify a subnet range
allow from 198.198.* #specify an IP address wildcard 
deny from all

Disable directory browsing
For security reason it is always better to disable directory browsing so that people won’t know what files you have. The following code will do so.

Options All -Indexes

Adding MIME Types
If your server is not set up to deliver certain file like MP3 or SWF properly then you can add the MIME type for those through .htaccess.

AddType application/x-shockwave-flash swf

Change your default directory page
Through DirectoryIndex you can change your default landing page of your website. The default landing pages are index.html, index.php, default.php etc. But if want to change it to some other page then please use the following code.

DirectoryIndex filename.html

Protect .htaccess files

<files .htaccess>
order allow,deny
deny from all
</files>

Protect php.ini file

<files php.ini>
order allow,deny
deny from all
</files>
(Visited 40 times, 1 visits today)

Leave a Comment.