# Editing .htaccess files with cPanel or the command line

> Create and edit .htaccess files in cPanel's File Manager or over SSH to set redirects, rewrites and access rules.

Source: https://helpcenter.ruachost.com/developers/linux/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**.

> **Note:**
- The .htaccess file is a **hidden file** (dotfile). You may need to enable “show hidden files” in your file manager.
- If no .htaccess file exists, you can create one manually.
- Always make a **backup copy** before editing, since incorrect rules can break your site.

## Editing .htaccess in cPanel

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.

## Editing .htaccess via Command Line (SSH)

1. Connect to your account using **SSH**.
2. Navigate to your site’s root directory:

   - For **cPanel**:

     ```bash
     cd ~/public_html
     ```
3. Open .htaccess with Nano:

   ```bash
   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.
