How to Manage htaccess Files

Updated 25 February 2026 11 views FTP & File Management

Managing .htaccess Files

The .htaccess file is a powerful configuration file used by Apache web servers. It allows you to control URL redirects, security settings, caching, and many other server behaviours without modifying the main server configuration.

What Is .htaccess?

The .htaccess file (short for Hypertext Access) is a hidden configuration file placed in your website directories. It is processed by the Apache web server on every page request and can override server-wide settings for the directory it resides in and all subdirectories.

Viewing and Editing .htaccess

  1. Open the File Manager in cPanel.
  2. Click Settings in the top right and enable Show Hidden Files (dotfiles).
  3. Navigate to public_html and locate the .htaccess file.
  4. Right-click and select Edit to modify the file.

Common .htaccess Uses

Redirecting URLs

Redirect a single page to a new location:

Redirect 301 /old-page.html https://yourdomain.com/new-page.html

Forcing HTTPS

Ensure all traffic uses a secure connection:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Custom Error Pages

Display custom pages for errors:

ErrorDocument 404 /404.html
ErrorDocument 500 /500.html

Password Protecting a Directory

Restrict access to a directory with a username and password using AuthType, AuthName, AuthUserFile, and Require valid-user directives. Create the password file using the Directory Privacy tool in cPanel.

Important Precautions

  • Always back up your .htaccess file before making changes. A syntax error can make your entire website inaccessible.
  • Test changes immediately after saving by visiting your website.
  • If your site shows a 500 Internal Server Error after editing .htaccess, revert to the backup to restore access.
  • Use the cPanel Redirects tool for simple redirects instead of editing .htaccess directly if you are not comfortable with the syntax.

Was this article helpful?

Let us know so we can improve our docs.