Archive for the ‘Hosting Setup Manual’ category

.htaccess file hosting tutorial

September 16th, 2009

In this tutorial you will find out about the .htaccess file and the power it has to improve your website. Although .htaccess is only a file, it can change settings on the servers and allow you to do many different things, the most popular being able to have your own custom 404 error pages. .htaccess isn’t difficult to use as it is really just made up of a few simple instructions in a text file.

What is the .htaccess file for?

You may be wondering what the .htaccess can do, or you may have read about some of its uses but don’t realise just how many things you can actually do with it.

There is a huge range of things .htaccess can do including:

  • Password protecting folders;
  • Redirecting users automatically;
  • Custom error pages;
  • Changing your file extensions;
  • Banning users with certain IP addresses;
  • Only allowing users with certain IP addresses;
  • Stopping/allowing directory listings; and
  • Using a different file as the index file to name just a few

Creating an .htaccess File

An .htaccess file is essentially a text file with no file name but an 8 letter file extension. Some earlier systems (e.g. Windows 3.1) made saving this file a bit difficult as it does not comply with the majority of file extension parameters. However, most modern operating systems will have no problems letting you save it. The easiest way is to create a basic text (*.txt) file and when you have finished editing it, simply change its name to:

“.htaccess” – (excluding the quotes and with no characters in front of the dot )

If you run into problems saving the file, you will need to name it something else (e.g. htaccess.txt) and then upload it to the server. Once you have uploaded the file you can then rename it using an FTP program.

Warning – Using With Microsoft FrontPage Extensions

Although using .htaccess on your server is extremely unlikely to cause you any problems (if something is wrong it simply won’t work), you should be wary if you are using the Microsoft FrontPage Extensions. The FrontPage extensions use the .htaccess file so you should not really edit it to add your own information. If you do want to (this is not recommended, but is possible) you should download the .htaccess file from your server first (if it exists) and then add your code to the beginning.

Using Custom Error Pages

The first use of the .htaccess file which I will cover is custom error pages. These will allow you to have your own, personal error pages (for example when a file is not found) instead of using your host’s error pages or having no page. This will make your site seem much more professional in the unlikely event of an error. It will also allow you to create scripts to notify you if there is an error (for example I use a PHP script on Free Webmaster Help to automatically e-mail me when a page is not found).

You can use custom error pages for any error as long as you know its number (like 404 for page not found) by adding the following to your .htaccess file:

ErrorDocument errornumber /file.html

For example if I had the file notfound.html in the root directory of my site and I wanted to use it for a 404 error I would use:

ErrorDocument 404 /notfound.html

If the file is not in the root directory of your site, you just need to put the path to it:

ErrorDocument 500 /errorpages/500.html

These are some of the most common errors:

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

Then, all you need to do is to create a file to display when the error happens and upload it and the .htaccess file.

How To Restrict Directory Access by IP Address using the .htaccess file

This can be a very effective way to protect certain directories on a domain. Any other directory in public_html can be protected in the same way. This method only works if you have a static IP address assigned to you. Anyone attempting to browse such directories using a different IP Address will get a 403 Forbidden error.

  • In the directory you wish to protect, open/create your .htaccess file.
  • Add the following code to this file, replacing 100.100.100.100 in this example with the static IP address you plan to allow:

    Order Deny,Allow
    Deny from all
    Allow from 100.100.100.100

  • Optional: You can enter partial IP Addresses, such as, 100.100.100. This allows access to a range of addresses.
  • Optional: You can add multiple addresses by separating them with comma’s.

    100.100.100.101, 100.100.100.102

How To Allow Directory Listings using the .htaccess File

  • In the directory you wish to allow viewers to see a list of its contents, create/open your .htaccess file – you may need to enable “show hidden files” in your ftp client or site editor to see the .htaccess file
  • On a free line type the following command:

    Options +Indexes

  • Save your .htaccess file and try creating uploading a few files – note: always use dashes or underscores in place of spaces for files being uploaded to the web.

Notes:
1. We do not recommend doing this on your root directory
2. To remove this capability, either delete the line added or replace the + with a -.

Using A File Other Than The Index.html As Your Home Page

By default the home page of your website is generally the index.html file(or maybe index.php if you’re using a database solution) as this is the file a browser will automatically look for on arrival at your site. However, there may be times where you would like to have your home page set to use another file in your site instead, e.g. home.html.

To do this is quite simple using the .htaccess file and the “redirect 301″ command. This form of redirect is commonly used to redirect viewers to a completely different website altogether.

In this example we will redirect to a file called home.html:

  • In the folder that contains the index.html and home.html files, open/create your .htaccess file.
  • At the top of the page enter the following:

    redirect 301 /index.html http://www.yourdomainname.com/home.html

  • Save the .htaccess file and your done.
  • Now test the redirect by entering the domain name into the address bar of your browser and hit go/enter. If the redirect is working properly, the address displayed should change to http://www.yourdomainname.com/home.html and display your home page.

Redirecting A Parked Domain To Your Main Domain Using The .htaccess File

Having multiple domains for the same site is now quite common. To add them to a site most people use the ‘Parked Domain” function so anyone who types them in will see your main site. However, from a search engine optimisation point of view this is not the best thing to do.

With a search engine like Google for example, you may loose ranking status for having duplicate versions of your site online. When Google searches it sees your sites content attached to number of domains and basically counts this as a form of content spamming, instantly decreasing your possible ranking status. And the more parked domains you have, the bigger the impact on your rankings.

If you’re hosted on an Apache powered server however, this negative effect of parking domains can be avoided by using the servers mod rewrite function. The bonus of this method is that the redirect will also be telling the search engines that any previously indexed information has simply been moved to your main site and has not disappeared. This will mean you won’t lose any ranking status already applied to any particular page in your site.

To perform this redirect place the following code into the .htaccess file in your root folder:

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

If you have multiple parked domains or want to always remove the “www.” you simply repeat the “RewriteCond” line for each parked domain with and without the www:

RewriteEngine On
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$
RewriteRule ^(.*)$ http://maindomain.com/$1 [R=301,L]

Transferring your site to Version-next

September 16th, 2009

Already hosted with another provider? Want to move your website to Version-next? This tutorial will outline the steps required to migrate your website and email accounts to your new Ausweb account.

Step 1 – Backup your files

First of all, you need to download the site from your old host. You can do this in one of two ways:

Backup your site through cPanel

If your old host uses cPanel, and the Backup feature is enabled, you can download your entire site in a couple of clicks. Follow the tutorial below which shows you how to download your site from your old host, and how to restore it on your Ausweb account.

Backup your site via FTP

If your host does not use cPanel or they do not have the backup function enabled, then you should backup your site using FTP. Typically you need to connect to your website via FTP, download your www or public_html folder (the names for this folder differ; it is the folder that contains your website) The tutorials below will show you how to connect and transfer files using the popular free FTP client Filezilla.

Step 2 – Backup and restore your MySQL databases

If you do not have any MySQL databases, you can skip to Step 3.

To transfer MySQL databases from your old host to Ausweb, there are two methods you can use:

Backup/Restore MySQL databases via cPanel

This uses the same cPanel function as the file backup section does. Simply follow the tutorial below to backup/restore your MySQL databases in a few clicks.

Backup/Restore MySQL databases via phpMyAdmin

If your host does not use cPanel/the backup function is disabled, you can backup and restore MySQL databases using phpMyAdmin. Follow the tutorials below for instructions on how to import and export MySQL databases in phpMyAdmin.

Step 3 – Upload your files to your Ausweb account

Now you need to upload your files to your Ausweb account. If you backed up your files using the cPanel backup feature, you can upload them easily through your Ausweb cPanel by following the tutorial above (“Backup and Restore your website through cPanel”)

If you backed up your files using FTP, simply connect to your Ausweb account using Filezilla and upload your files into the public_html folder.

Step 4 – Create email accounts on your Ausweb account

Before you point your domain to your Ausweb account, its a good idea to create the email addresses through cPanel first. Simply create the email addresses you want on your Ausweb account by following the tutorial below:

Step 5 – Point your domain to your Ausweb account

By this point your account with Ausweb should mirror your account at your current host; you should have uploaded your site files and MySQL databases and created your email accounts. Once you are sure you have completed all the steps above, its time to change the nameservers of your domain.

Login to your domain control panel at your registrar and modify the nameservers for your domain to the ones we sent you in the welcome email. Video guides for modifying nameservers for most of the major registrars are listed here:

Once you have done this, wait for your domain to propagate. This can take between 6-72 hours, depending on your location. To see if your domain has resolved correctly to your Ausweb account, type your domain name into the tool below and hit Lookup. On the next page scroll down to the Whois Record section. If the Ausweb nameservers are listed here, then your domain name has resolved.

Check your domain name is displaying correctly, and then proceed to the next step.

Step 6 – Cancel your account at your old host

Once you have updated your nameservers and your domain name has resolved correctly, you can cancel your account at your old host. Make sure you backed up all your files; getting data back after you have cancelled your service with a provider can be quite difficult.

Uploading your website via FTP

September 16th, 2009

Once you have created your new account with Version-next, you can access it using the details provided in your web hosting welcome email. If your domain name is not officially pointing to our servers yet, use the IP address and the Username which was sent to you in your welcome email.

Example:
ftp host: yourdomain.com.au or the temporary IP address
ftp username: your cpanel username
ftp password: your cpanel password

Where do I upload my files to?

The public_html is where your web page files and folders have to be placed !!!!

The public_html folder is the only folder you should be uploading your website files and folders to. For your site to be accessible directly by your domain name name, your index file(index.htm, index.html, or index.php) has to reside directly inside the public_html folder. You must also make sure that you maintain exactly the same file/folder layout structure as the one that is in your HTML editing application. If you do not maintain this layout your web pages will not be able to correctly reference each other or any embedded images, etc.

Below is an example of how a basic structural layout of a site may look once it has been uploaded. Please bare in mind this is only a sample and your site’s files and folders may be named differently to those listed.

Deleting files and folders

It is VERY IMPORTANT you do not delete any system folders when transferring or removing files. Doing so can corrupt your hosting account. Only remove files and folders that reside inside the public_html folder.

PHP Freelancer