Cart

    Sorry, we could not find any results for your search querry.

    Using an .htaccess file

    An .htaccess file (with the dot in front) is a file type for websites that run on an Apache web server. You can perform various actions and even change, activate and bypass some (server) settings with an .htaccess file.

    In this article we'll show you how to create a .htaccess file and how to use them.


    Creating an .htaccess file

    An .htaccess file is nothing more than a simple text file created by opening Notepad on your Windows computer or (recommended) with Notepad++.

    When saving a .htaccess file in Notepad, it may get saved as .htaccess.txt. This requires you to rename the file after saving it. On the other hand Notepad++ allows you to instantly save it as .htaccess, but it also offers tons of other features for you to use.

    In your .htaccess file, you add lines of code which makes the web server perform actions or change settings for your website. You then upload the .htaccess file to your website using SFTP software, such as Filezilla or Cyberduck. If you use a web hosting package, you can also upload your .htaccess file using SFTP filemanagement in your control panel.

    Using SFTP, upload the .htaccess file to the website folder you want it to apply to. For example, if you want to apply an .htaccess file on your main domain (e.g. yourdomain.com), upload it to the /www folder. If you want to apply the .htaccess file to a subdirectory (e.g. yourdomain.com/images/), upload it to the /images folder inside the /www folder.


    Examples of .htaccess files

    • Redirecting your visitors to a different address on the internet is a simple but frequently used feature of .htaccess. For more information about .htaccess redirects, read the article 'Redirect your website using .htaccess'. 
       
    • An .htaccess file can also allow you to secure (a part of) your website. Read more on this in the article 'Password protection for your website'.

    These are just a handful of examples on how to use .htaccess to change the behaviour of your website. There are tons of other features to use .htaccess for, too many to fit into one article. We recommend visiting 'Htaccess Guide' for a comprehensive guide on most .htaccess features.

    If you have a WordPress website, an .htaccess file will most likely already exist. In that case, make sure you edit the existing .htaccess file and adding new lines at the top of the file.


    Keep in mind that we do not offer direct support on configuring .htaccess files. However, the information found online regarding .htaccess files can be applied to our web servers without any difficulties.


    Redirecting a website

    In the image below you see an example of an .htaccess file from the article 'Redirect your website using .htaccess'.

    example from redirect your website

    The first line starts with a symbol, indicating what the line below does. The text after the symbol is not an active part of the .htaccess file.

    The second line is:

    Redirect 301 / https://transiptutorials.com/

    This line executes a simple action: Using a 301 redirect, send visitors from my website to the address https://transiptutorials.com.


    Blocking a location

    If you want to block a specific location from visiting your website, you can do so by adding a few lines to the .htaccess file. Below you will find an example, you can change the country codes to those of different countries.

    # block China and Russia access
        <IfModule mod_geoip.c>
        GeoIPEnable On
        SetEnvIf GEOIP_COUNTRY_CODE CN BlockCountry
        SetEnvIf GEOIP_COUNTRY_CODE_V6 CN BlockCountry
        SetEnvIf GEOIP_COUNTRY_CODE RU BlockCountry
        SetEnvIf GEOIP_COUNTRY_CODE_V6 RU BlockCountry
        Deny from env=BlockCountry
        </IfModule>

     



    In this article we explained how to create and use .htaccess files.

    If you have any questions regarding this article, please contact our support team. You can reach them using the 'Contact us' button below or via the 'Contact' button inside your control panel.

    Need help?

    Receive personal support from our supporters

    Contact us