How to configure your .htaccess

Some of the configurations on the web server designated for shared hosting are set up by the administrator of the hosting and cannot be changed by users (for example, the disk space limit for a hosting or email account, the data transfer limit, etc.). However, there are some configurations that can be changed at the user level. You can change these configurations by creating a file called .htaccess in the root directory of your domain via FTP. The configurations set in this file apply to the directory where the .htaccess file is located, as well as to all directories at the levels below it. If there is another .htaccess file in one of the subdirectories, the configuration of this file overrides the settings for any previous file level for that subdirectory.

The .htaccess can set a number of parameters and control access. This file is used for:

    • Configuring user-friendly URLs
    • cache control
    • restricting access to directories or files
    • setting other parameters

IMPORTANT: You cannot configure the php_flag and php_value parameters in your .htaccess file on our hosting. If you include these parameters in your .htaccess file, an error will be displayed on your main page.

Below is an example of some commonly used directives that you can set in the .htaccess file. We assume that you place the .htaccess file in the root directory of a domain via FTP.

Directive Options:

    • Options -Indexes - if there is no index.html or index.php file in the directory where the .htaccess file is located, a 403 error will be displayed on the main page. If there is an index.html or index.php file in the main directory, you will see the contents of that file. Our hosting enforces such indexes, so there is no need to include this directive.
    • Options +FollowSymlinks - tells the web server to follow so-called symbolic links. Symlinks are disabled on our hosting for security reasons
    • RewriteEngine On - allows you to set up redirects between domains and subdomains, enable friendly URLs and more

If you do not use .htaccess, your links may look like this: happyuser.zzz.com.ua/index.php?q=webpagename. It's hard to remember and read this address. To make it easier, the so-called friendly addresses were invented. If you configure your .htaccess to use a friendly URL, your address will look like this: happyuser.zzz.com.ua/webpagename.

Let us take a look at how to enable the use of friendly URLs:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) index.php?q=$1 [L]

Another feature commonly used in .htaccess is to restrict access to specific directories or files located on the FTP. You can make them accessible only to the site owner or the FTP server, but not to visitors to the site. To do this, create an .htaccess file in the desired directory with this directive: Deny from all. Then, if anyone tries to get into the directory, the web server will return a 403 Forbidden error. However, the owner of the website can access this directory via FTP.

Another option you can use with the .htaccess file is to redirect www.yourdomain.com to yourdomain.com - if you want your domain to be visible without the www prefix. To set up this redirect, create an .htaccess file with these rules in it:

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

There are many more directives you can use in .htaccess to configure your website.