Customer Support

  1. Support
  2. FTP/ File Manager
  3. What is and how to use the .htaccess file?
  1. Home
  2. Plesk
  3. What is and how to use the .htaccess file?

What is and how to use the .htaccess file?

Through the .htaccess file, you can make settings related to your hosting, easily, quickly and without having special programming knowledge.

How to create a .htaccess file?

Open a text editor like notepad or notepad++ and create a new empty file and save it with .htaccess extension

Note 1: In case there is already an .htaccess file on the hosting site, download it locally to make the desired changes, save and re-upload it to the server.

Note 2: Some text editors do not support the .htaccess format, so save it with .txt extension, upload it to the server and rename it to .htaccess

In what situations do I use the .htaccess file?

1. In case you want to create your own error pages, when there is an error on your site. The most popular error pages are the following:

500 Internal Server Error. Appears when there is a problem with Hosting, which can be due to various causes.

403 Forbidden. Occurs when users try to access a file (code, web file, graphic, etc.) whose permissions do not allow such actions.

401 Authorization required. This page appears when users try to access code-recommended pages and have entered the wrong login information.

404 Not found. It appears when users try to visit a page that doesn't exist on your site.

You can keep the main message of the page so that the error is clear and edit them visually. Save the changes you've made anywhere on the server you want and set them to appear accordingly.

For example, if you have created and modified the 401.htm page, you should insert the following line into your .htaccess file:

ErrorDocument 401 /401.html

If you named your error page "notfound.html" and stored it in a subfolder named "errorpage" then the line you would insert into your .htaccess file is:

ErrorDocument 404 /errorpages/notfound.html

2. When you want to hide folders of a directory so that a directory of your files is not displayed, to avoid hacking, the command you should add to .htaccess is the following:

Options -Indexes

Note: All Top.Host hosting packages have this feature enabled by default, hiding your files, so it is not necessary to create the above command.

3. In case you want to block specific IP addresses from accessing your site, add the following command:

order allow,deny
deny from IP (the ip you want to block)
allow from all

If you want to block more than one IPs, add them one below the other as shown in the example below:

order allow,deny
deny from 185.4.135.1
deny from185.4.135.5
allow from all

You can block IPs in bulk by adding the IP number to the penultimate digit:

order allow,deny
deny from 185.4.135.1
deny from185.4.135.
allow from all

4. When you want to redirect files to some other path. For example if you have the file Tophostoldpage.htm and want to redirect it to another file, enter the following command:

Redirect / Tophostoldpage.htmhttp://www.Tophost.gr/new/file/location.html

If the old file is in a subfolder, eg old/Tophostoldpage.htm, then the command is:

Redirect /old/ Tophostoldpage.htm http://www.Tophost.gr/new/file/location.html

Also, you can redirect entire directories of your site. For example, if you have a directory with subfolders and files on your old site and you have added the same files to the new one. To do this, the command you will need to enter is the following:

Redirect /olddir http://www.newsite.com/newdir

Also, you can redirect from a domain without "www" to the same domain with "www". For example, when a user opens the site "top.host" to automatically direct them to www.top.host the command you should enter is:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^top.host [NC]
RewriteRule ^(.*)$ http://www.top.host/$1 [L,R=301]


You haven't found what you are looking for?

Contact our experts, they will be happy to help!

Contact us