More .htaccess Examples

Deny/Allow Certain IP Addresses
Block an IP Address

#Deny List

order allow,deny
deny from #specify a specific address
deny from #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 #specify a specific address
allow from #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

Protect php.ini file

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

Leave a Comment.