Skip to content

Editing .htaccess Files with cPanel, or the Command Line

The .htaccess file is a configuration file used by the Apache web server to control how your website behaves. It can be used for tasks such as redirects, password protection, enabling compression, or rewriting URLs. This article explains how to create and edit .htaccess files in cPanel, or via the command line.

  1. Log in to your cPanel account.

  2. Go to Files → File Manager.

  3. Navigate to the public_html folder.

  4. If you don’t see .htaccess:

    • Click Settings (top right).
    • Check Show Hidden Files (dotfiles).
    • If still missing, click + File and name it .htaccess
  5. Right-click .htaccess → Edit.

  6. Add or modify rules as needed.

  7. Click Save Changes.

  8. Test your site to confirm everything works.

  1. Connect to your account using SSH.

  2. Navigate to your site’s root directory:

    • For cPanel:

      Terminal window
      cd ~/public_html
  3. Open .htaccess with Nano:

    Terminal window
    nano .htaccess
    Add or modify rules.
  4. Save changes:

    • Press Ctrl + O, then Enter.
    • Exit with Ctrl + X.
  5. Test your site to confirm everything works.