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.
Editing .htaccess in cPanel
Section titled “Editing .htaccess in cPanel”-
Log in to your cPanel account.
-
Go to Files → File Manager.
-
Navigate to the public_html folder.
-
If you don’t see .htaccess:
- Click Settings (top right).
- Check Show Hidden Files (dotfiles).
- If still missing, click + File and name it .htaccess
-
Right-click .htaccess → Edit.
-
Add or modify rules as needed.
-
Click Save Changes.
-
Test your site to confirm everything works.
Editing .htaccess via Command Line (SSH)
Section titled “Editing .htaccess via Command Line (SSH)”-
Connect to your account using SSH.
-
Navigate to your site’s root directory:
-
For cPanel:
Terminal window cd ~/public_html
-
-
Open .htaccess with Nano:
Terminal window nano .htaccessAdd or modify rules. -
Save changes:
- Press Ctrl + O, then Enter.
- Exit with Ctrl + X.
-
Test your site to confirm everything works.