A .htaccess (hypertext access) file is a directory-level configuration file supported by several web servers, that allows for decentralized management of web server configuration.The original purpose of .htaccess – reflected in its name – was to allow per-directory access control, by for example requiring a password to access the content. Nowadays however, the .htaccess files can override many other configuration settings including content type and character set, CGI handlers, etc.These files are placed inside the web tree, and are able to override a subset of the server’s global configuration for that directory, and all sub-directories
Category Archives: .htaccess
Protect a file using .htaccess
Add the below given code in your .htaccess file
<files filename.php>
order allow,deny
deny from all
</files>
Blacklist IP addresses
You can blacklist IP addresses using the below given code in htaccess file
General Format
=========
allow from all
deny from xxx.xxx.xxx.xx
Example
=====
allow from all
deny from 115.100.22.11
How to speed up your site using .htaccess
You can speed up the site by enabling file caching General Format <FilesMatch “.(Extenstion of the file to be cached)$”> Header set Cache-Control “max-age=cache time″ </FilesMatch> Example <FilesMatch “.(html|htm)$”> Header set Cache-Control “max-age=43200″ </FilesMatch
Protect your site from hotlinking
You can protect your site from hotlinking by adding the below given code in your htaccess file .
RewriteEngine On
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://([ -a-z0-9] .)?domain.com [NC]
RewriteRule .(gif|jpe?g|png)$ – [F,NC,L]
Redirect to a secure https connection
Add the below given code in your htaccess page to redirect to https connection
RewriteEngine On
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
Restrict maximum execution time – .htaccess
php_value max_execution_time 200
php_value max_input_time 200
Restrict file upload limits using .htaccess code
php_value upload_max_filesize 10M
php_value post_max_size 10M
Set up a 301 redirect
If you rename the url of a page and need to redirect old URL to your new page, use the below given code in your htaccess page
Redirect 301 old_file_name.html http://example.com/new/file_name.html
Set the default page of each directory
You can set any page as a default page in a directory by adding below given code in your .htaccess file
DirectoryIndex firstpage.html