Jump toSuggest an edit

How to configure an .htaccess file

Reviewed on 02 February 2024Published on 05 August 2021

This documentation describes the usage of a previous web hosting offer proposed by
Refer to the Scaleway Web Hosting documentation for information about the current web hosting product.

.htaccess is a simple text file containing commands for the configuration of the Apache web server. It allows you to personalize the server dynamically and per folder.

  • When you transfer your .htaccess file, ensure the FTP transfer mode is set to “ASCII/TEXT” and not to “BINARY”. If the file is transferred in binary mode, you will get an HTTP error 500. Your .htaccess must end with an empty line, if it is not the case you will get an error 500. This will block the access to your websites. Therefore, double-check the file syntax before transferring it by FTP in text mode and not in binary mode.
  • You can create the .htaccess file on Windows only using Notepad.

How to configure personalized error messages?

This function allows you to replace the message of a 404 error (Not found) for a more friendly text or with a redirection to another URL, whether local or external.

  1. Use the command ErrorDocument to configure personalized messages. Below are some examples of how to use it:
    ErrorDocument 404 http://URLexample.tld
    ErrorDocument 403 /accessrefused.html
  2. Make sure this command is in an .htaccess file in the directory to which you wish to redirect the error messages. The directory is typically the root of your website, but not necessarily.

How to disable the listing of a directory?

  1. Create an .htaccess file by opening your text editor.
  2. Create a text file containing the following line:
    Options -Indexes
  3. Upload your file using FTP, place it in the directory of your choice, and rename it to .htaccess.

How to prevent access to a directory?

  1. Open your text editor and create a text file containing the following line:
    Allow from
    # We authorize to access from the IP
    Allow from
    # We deny the access from all other IPs
    Deny from All
  2. Upload your file using FTP, place it in the directory of your choice, and rename it to .htaccess.

How to secure a directory with an HTTP authentication?

  1. Create a user table, which is a list of the users and their passwords. Below is an example of what your user table should look like:

    • The first part is the username, and the second part after ”:” is the encrypted password of the user.
    • If required, you may use this website to encrypt your passwords.
  2. Name this file passlist.txt.

  3. Create an .htaccess file in the directory you want to protect to limit the access to the users specified in the file passlist.txt. The content of the file should be as follows:

    AuthUserFile /PATH/passlist.txt
    AuthName "Acces Restricted"
    AuthType Basic
    require valid-user
    • Replace PATH by: /flex/domain/DOMAIN.TLD/site/www/.
    • Replace DOMAIN.TLD with your domain name.
    • The command AuthUserFile specifies the path to the user table. The path is relative to / of your web hosting, therefore your path will generally start with at least www/ or blog/.
  4. If you have saved your user table in the directory /www/secret/password/ with the name mylist.txt you need to change the AuthUserFile directive accordingly:

    AuthUserFile /flex/domain/DOMAIN.TLD/site/www/secret/password/mylist.txt
    • The command require valid-user authorizes all valid users to access the files in the folder. It is also possible to use require user martin sophie to only authorize the users Martin and Sophie and to exclude Jean.
  5. Upload the file using FTP, place it in the directory of your choice, and name it .htaccess. If you want to learn more about this, we recommend the Apache user guide, which treats all aspects of authentication in detail.

    • It is not possible to create an .htaccess file directly on the Microsoft Windows platform. Therefore, you need to create the file with another name, “htaccess.txt” for example on your computer and rename it after you have uploaded it to your server.
    • You must transfer the file in the ASCII mode (refer to the documentation of your FTP client) to make sure that the ‘line break’ characters are preserved.
    • It is highly recommended to protect its list of passwords, for example, you can store it in a subdirectory of your website that you protect by creating an .htaccess file.

How to configure HTTP redirections

  1. Create an .htaccess file with the following content:
    RedirectPermanent /
  2. Upload the file using FTP in the folder of the concerned subdomain (folder www for www.URLexample, blog for blog.URLexample etc.) and name it .htaccess.
    • Take a look at the documentation on the Apache website for more information.

How to configure an HTML redirection

  • This method is simpler but less efficient, it uses the HTML document itself to indicate the redirection. This method should only be used when HTTP redirects are impossible.

Here is an example of the redirection of to

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "">
<html xmlns="">
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<meta http-equiv="refresh" content="0; url=" />
<meta name="robots" content="noindex,follow" />
<p><a href="">Redirection</a></p>

How to configure PHP redirects

Create a PHP file containing the following content to redirect http://URLexample/index.php/ directly to

  • By default, the redirection returns the code HTTP 301. Do not forget to modify it, if required.

How to rewrite Rules

  • The Apache module mod_rewrite is activated on our web hosting servers, and it works by default with .htaccess files.
  • The directive FollowSymlinks is activated and must not be modified. Doing so will result in an HTTP 500 error.

Let us do an example, the domain name is URLexample, the URL we are going to call is http://www.URLexample/index.php/ with the name of the page as argument.

  1. Create an htaccess file with the following content:
    RewriteEngine On \\
    RewriteRule ^([^\.]+)\.html /index.php?page=$1 [L]
  2. Upload the file using FTP in the folder of the concerned subdomain (Folder www for www.URLexample, blog/ for blog.URLexample etc.) and rename it .htaccess.
  3. Open the http://www.URLexample/test.html/ file in your web browser, index.php will be executed with the argument “test”.
See also
How to solve email account connection problemsHow to configure PHP
Docs APIScaleway consoleDedibox consoleScaleway LearningScaleway.comPricingBlogCarreer
© 2023-2024 – Scaleway