Adding MIME Types by .htaccess file

htaccess file, Programming
In case your web hosting account is not configured to server certain mime types with the proper content type. You can change this using .htaccess file.A common occurrence with MP3 or even SWF files. Simple enough to fix: AddType application/x-shockwave-flash swf; AddType is specifying that you are adding a MIME type. The second part is the MIME type, The application string is the actual parameter of the MIME you are adding, and the final little bit is the default extension for the MIME type you just added, in our example this is swf for ShockWave File. AddType text/html htm0 the final part is the file extension, in this example 'htm0'.
Read More

How to Change the default Directory Index in Apache Server by .htaccess file ?

htaccess file, Programming
The index of a directory can come from one of two sources: A file written by the user, typically called index.html. The DirectoryIndex directive sets the name of this file. This is controlled by mod_dir. Otherwise, a listing generated by the server. This is provided by mod_autoindex. Method 1:- Edit the httpd.conf file This method can only be done by Server administrator. This method is suited for someone who uses a dedicated server/VPS. Open the httpd.conf file using a text editor and search for the following line. DirectoryIndex index.html index.htm index.php Add the file names at the end of the second line with a space. Take a look at the following example DirectoryIndex index.html index.htm index.php home.html myname.php jesin.htm In this way you add all the desired file names. Finally…
Read More

How to Block Bad Bots, Site Rippers, Crawlers, Scrapers and Malwares by .htaccess file

htaccess file, Programming
We often seen that some unidentified bots relentlessly use bandwidth of website that cause the loading speed of website become slow and affects the ranking position on search engines like Google, Yahoo, and Bing etc. Bad bots, scrapers and malwares are unwanted visitors to site and harmful to server bandwidth.  Bad bots as they are often called refers to programs which visit your web site, either to source content, look for security holes or to scan for email addresses. This is often how your email address ends up on 'Spam' databases, because they have set a 'bot' to scan the Internet and collect email addresses. These programs and 'bots' often ignore the rules set out in 'robot.txt' files. RewriteEngine On RewriteCond %{HTTP_USER_AGENT} ^AbachoBOT [OR] RewriteCond %{HTTP_USER_AGENT} ^anarchie [OR] RewriteCond %{HTTP_USER_AGENT}…
Read More

How to Hot Link Protect Your Files by .htaccess File

htaccess file, Programming
The hot link Protection technique allows you to prevent other websites from directly linking to files on your website. This is most commonly used to prevent other web sites from displaying your images but it can be used to prevent people using your JavaScript or CSS (cascading style sheet) files. The problem with hot linking is that it uses your bandwidth, which in turn costs money, hot linking is often referred to as 'bandwidth theft'. If you are using hot link protection technique, other websites that hot link to your files will display an error or show nothing. This means that when another website is visited, it cannot load pictures from your pages - this is one of the ways for limiting the outbound traffic for your account. An example…
Read More

How to Block Visitors from Spam Referrers By .htaccess file

htaccess file, Programming
When you notice a surprising increase in traffic and check your logs one day, and see tons of referrals from a particular site, yet upon inspection you can't find a single visible link to your site on theirs.  The referral isn't a "legitimate" one, with the site most likely pinching content or hot linking to certain files on your site such as images, .css files, or files you can't even make out it means that someone is attempting to hack your web site (this may simply mean trying to find non public content). You will another big usage of .htaccess file: Blocking users or sites that originate from a particular domain. The following code will block any visitor by referrer: RewriteEngine on Options +FollowSymlinks RewriteCond %{HTTP_REFERER} thisbad_domain\.com [NC] RewriteRule .* -…
Read More

Password Protect A Directory or A Single File by the .htaccess file

htaccess file, Programming
Protecting files on your website from unauthorized users can be very important. You could use PHP to listen for login authorization information on each page, but that doesn't protect your images, documents, and other media?  The password protection and authentication systems offered by the Apache Web Server are probably one of the most important use of .htaccess file.  Very easily, we can password protect a directory (or multiple) of a web site which require a username and password to access. Password Protection for a Directory The method is called htaccess password protection or htaccess authentication, and works by uploading One file called .htaccess  in the directory you want to password protect.  The htaccess file should contain the following: AuthType Basic AuthName "The Member Zone Name" AuthUserFile /path/to/password/file/.htpasswd require valid-user It…
Read More

Custom Error Responses by .htaccess ErrorDocuments following HTTP response status codes

htaccess file, Programming
One of the important use of the .htaccess file is to redirect users to a custom error page depending on the specific web server error they encounter.  Your website visitors need know why the page which he/she is visiting does not exist any more, what happens to the page that he is visiting. Search Engine like google need know why the pages are missing too. For good visitor experience and good SEO results, you need customer error pages. Creating custom error pages is very useful, it allows you to show web site visitors and search engines a friendly error message, for instance if a URL on your web site does not work. This avoids the unfriendly ‘404 File Not Found’ error and allows you to display a friendly error, explaining…
Read More

How to Redirect By .htaccess File ?

htaccess file
Redirects enable us to direct web site visitors from one document within your web site to another directory within your website or another website's directory or file. This is useful if you want to direct your traffic from one websites to another , or from one directory to another directory. Mostly useful for traffic direction and SEO services. There are several kinds of redirects using .htaccess file 301 (Permanent) Redirect:  Direct your whole website to a different URL on a permanent basis. This is the most common type of redirect and is useful in most situations. In this example, we are redirecting to the "powerhoster.com" domain: #This allows you to redirect your entire website to any other domain Redirect 301 / http://powerhoster.com/ 302 (Temporary) Redirect:  Direct your whole website to…
Read More

How to deny IP addresses by .htaccess

htaccess file, Programming
To ban a single IP address from accessing your Website, add following code to the .htaccess file in the root directory of your html file. If you donot have .htaccess file in your root directory, you can create one. FTP and file manager can help you to create .htaccess file. Please remember the "." before htaccess. "." means hidden file. order allow,deny deny from 79.09.9.8 deny from 221.138.7 allow from all The above lines tell the Apache Web Server to block visitors from the IP address '79.09.9.8' and '221.138.7', note the second IP address is missing the fourth set of digits, this means any IP address which matches the firth three set of digits will be blocked, e.g. '221.138.7.1' , '221.138.7.2' till '221.138.7.255' would be blocked. If you want to block…
Read More