.htaccess overview and some examples

This overview will explain a little bit what it is .htaccess and how to maximize your website
Although .htaccess is a file, but .htaccess can change the settings on the server and allow you to do many different things, as an example is to use .htaccess you can create your own 404 page.
.htaccess is not difficult to use because it only needs to put some instructions in a simple text file which is then saved with the name .htaccessat purpose .htaccess?

Perhaps you wonder what can be done by the .htaccess, or you may have read about it but does not realize that many things you can do with .htaccess.

Here are some of functions .htaccess

* Folder protection / Protect Folder with password
* Automatic redirect your website visitor
* Make erorpage display on your own
* Reject the visitors with a specific IP Address
* Changing your file extention
* Only allow visitors with a specific IP Address
* Allow / Reject list directory

Create .htaccess file

.htaccess file is a text file that has no name but has 8 extentions letters in length.
An easy way to create this file by creating a file ending .txt and then after you are finished making them, you change it to .htaccess extention.

If you have trouble changing the name of the file you can change into htaccess.txt and then upload the file to your hosting account. After the file uploads you can change the name to use FTP program that you own or use the File Manager you can access through your CPANEL.

Create your own error message page

By using .htaccess you can create an error page that can be used to your own website and no longer use the default settingan from the server.
By using the error page itself can make your site look more professional in handling the errors that occur even allow you to create a script that can alert you when the error occurred.

You can use your own error message as long as you know the code that is used (such as 404 for a page can not be found / page not found) by adding the command below into the file .htaccess you:

ErrorDocument code /file.html

For example, if you have any notfound.html file in the root directory of your website and want to use it for 404, you can use the line below:

ErrorDocument 404 /notfound.html

If the file is not located in the root directory of your website, you only need to add a directory structure to them, for example:

ErrorDocument 404 /error/notfound.html

Here is the error message that often happens:

401 – Authorization Required
400 – Bad request
403 – Forbidden
500 – Internal Server Error
404 – Wrong page

Then, you need to do is create a file to display an error message when an error has occurred and uploaded files are, do not forget to upload the file .htaccess you.

How do I restrict access to directories based on IP address using .htaccess file?

This can be in a way that is effective to protect the directory is in a domain / site.
Folders other than those located in the public_html folder can also be protected in the same way.
This method can only be run if you have a hosting account with a static IP address itself.
Anyone who tried to visit the directory that is protected will get an error message 403 Forbidden error.

Steps to make:

* In the directory you want to create a protected or open .htaccess files.
* Put the code below and replace 100100100100 is in this example with the IP Address you want to allow.

Order Deny, Allow
Deny from all
Allow from 100100100100
* Additional: You can enter part of the IP Address, such as, 100100100
* Additional: You can add other IP Address with separated with commas, like this

100100100101, 100100100102
* Save .htaccess file and upload .htaccess if you are not in the upload.

Switch in the Domain Parking Domain to another

Have a different domain to the same site is a habitual thing.

To add domains to your website in the same, many people use the services “Parked Domain”, in which when someone visits the domain will direct you to open the website.
However in terms of search engine optimisation, this is not the best things that need to be doing.

With search engines such as Google as an example, you can lose the status ranking (PR) from the website because you have the same view for several different domains.
When the Google search and view the website you have the same contents with a different domain, then Google will be calculated as plagiarism or the content of the website content and will automatically reduce your PR status.
And the more Domain Parking you have, the greater the impact to the PR you have.

If you put your website on the server using the Apache, the negative effect of the domain parking can be avoid by using mod_rewrite function.
Bonus from the use of this method is also made to tell search engines that look the same that are in the domain parking is to move your website and do not disappear.
This means you will not be exposed to risk losing your PR status.

To do this redirect method, put the code below in .htaccess file you:

RewriteEngine On
RewriteBase /
RewriteCond% (HTTP_HOST) ^ www.parkeddomain.com
Http://maindomain.com/ RewriteRule ^(.*)$ $ 1 [R = 301, L]

If you have a domain parking more than one or you want to remove “www.” of the domain, you only need to repeat the line “RewriteCond” for each domain parking that you have and without the www.

RewriteEngine On
RewriteBase /
RewriteCond% (HTTP_HOST) ^ www.parkeddomain1.com [OR]
RewriteCond% (HTTP_HOST) ^ parkeddomain1.com [OR]
RewriteCond% (HTTP_HOST) ^ www.parkeddomain2.com [OR]
RewriteCond% (HTTP_HOST) ^ parkeddomain2.com
Http://maindomain.com/ RewriteRule ^(.*)$ $ 1 [R = 301, L]

Using a file other than the index on your website

By default, the first page of your website .* file is the index because this is the file that will be the first time by looking at your visitor’s browser so they visit your website.
But you may wish to change your website, to use the file name other than index .*.

To do this quite easily using the .htaccess file and the “301 Redirect”. Redirect is used to switch the regular website visitors long to your new website.

In this example you will switch to the file home.html:

* In the directory you wish to allow Directory Listing, create or open .htaccess files.
* Put the code below.

Redirect 301 / index.html http://www.yourdomain.com/home.html
* Save .htaccess file and upload .htaccess if you are not in the upload.
* Test results of your work by visiting the website you http://www.yourdomain.com namely, if successful then the address will appear to be http://www.yourdomain.com/home.html and display your website.

Allow Directory Listing using .htaccess file

Here’s how to allow your website visitors see Directory Listing of your website:

* In the directory you wish to allow Directory Listing, create or open .htaccess files.
* Put the code below.

Options + Indexes
* Save .htaccess file and upload .htaccess if you are not in the upload.

Incoming search terms:

2 Comments »

  1. avatar comment-top

    this will very helpfull to me … thanks  

    comment-bottom
  2. avatar comment-top

    nice post
    but i’m affraid some web hosting doesn’t allowed .htaccess file to be used on their server  

    comment-bottom

RSS feed for comments on this post. TrackBack URL

Leave a comment