How to Use or Modify the htaccess configuration file

CAREFUL! AN INCORRECT CONFIGURATION OF .HTACCESS FILES CAN RENDER YOUR WEB SITE INACESSIBLE

What is the .htaccess file?

The .htaccess file is a configuration file that can be used to modify the default configuration of your website's web server. If such a file exists, it is read by the server before each access via the HTTP or HTTPS protocol. The .htaccess file can be used to configure page or domain redirections, block certain IPs from your website, or enable certain types of caching.

How can I modify the .htaccess file?

One of the simplest ways is by using the File Manager, in your cPanel.

  1. Click on File Manager
  2. At the top right, click on Settings and ensure Show Hidden Files (dotfiles) is checked
  3. Click on the folder containing your website, or any folder you wish to affect. In most cases, this will be the public_html folder.
  4. If the .htaccess file already exists, you'll see it in the files view. Click on it and click on Edit in the top menu. If a dialog box asking you to confirm the encoding of the file pops up, simply click Edit again to continue. If you don't see an .htaccess file in the folder containing your website, you can create one bu clicking on +File in the top menu (remember to name it .htaccess).
  5. Make the changes you want to your .htaccess file, then save the file.
  6. You've just modified your .htaccess file! Make sure you test your changes. All it takes is one small error in this file to render your website completely inoperable. In case of errors, you can always disable your .htaccess file by simply renaming it (for example, to .htaccess.old)

If you prefer, you can also create the file with Notepad or any other application that can write documents in pure text (not Microsoft Word) and save it with the name ".htaccess" (no quotation marks) on your local workstation. You then need to transfer the file to the server via FTP, with a software such as FileZilla. The .htaccess file must be placed in the folder containing the HTML/PHP/other pages you want it to affect. It is important to note that the .htaccess file will affect all files in the folder and its subfolders, unless another .htaccess file exists in that subfolder.

Contents and syntax

Here are some articles explaining the .htaccess file:

https://httpd.apache.org/docs/2.4/howto/htaccess.html

http://www.javascriptkit.com/howto/htaccess.shtml

 

Article ID: #HC5022

Was this answer helpful?