How to Edit .htaccess in cPanel

The .htaccess file is one of the most powerful configuration documents on your SastoHost web server. It controls how your website handles permalinks, redirects, and even SSL security. However, because it starts with a dot (.), Linux servers automatically hide it from view to prevent accidental deletions. Here is exactly how to unhide and safely edit your .htaccess file.

Step 1: Force cPanel to Show Hidden Files

Before we can edit the file, we have to tell the File Manager to stop hiding it from us.

  1. Log in to your cPanel account and open the File Manager.
  2. Look at the very top-right corner of the screen and click the gear icon labeled Settings.
  3. A small preferences menu will pop up. Check the box that says Show Hidden Files (dotfiles).
  4. Click the Save button. The page will quickly refresh.

Step 2: Locate and Edit the File

Now that visibility is turned on, we can navigate to the file and open the built-in code editor.

  1. On the left-hand sidebar, double-click your public_html folder (or the specific root folder of the domain you are working on).
  2. Scroll through your files and locate .htaccess. (Note: If it still does not exist, you can simply click the "+ File" button at the top and create a new one named exactly ".htaccess").
  3. Right-click the file and select Edit from the dropdown menu.
  4. A character encoding box will appear. Leave it as the default and click the Edit button to open the file in a new browser tab.

Step 3: Modify and Save Safely

Because this file controls server behavior, even a single missing space or typo can take your entire website offline with a "500 Internal Server Error." Always proceed with caution!

  • Never delete existing code: Unless you know exactly what a rule does, paste your new code snippets either at the very top or the very bottom of the document.
  • If you are using WordPress, ensure you place any custom rules outside of the standard `# BEGIN WordPress` and `# END WordPress` tags, otherwise WordPress will overwrite your changes.
  • Once you have pasted your new redirect rules or security headers, click the Save Changes button in the top right corner.
  • Immediately open your website in a new tab to verify it is still loading correctly!

Did a change to your .htaccess file break your website? Don't panic! Simply go back into the editor, delete the code snippet you just added, and click save to restore your site instantly. If you are still stuck, open a support ticket and our SastoHost team will gladly assist you.

Was this answer helpful? 0 Users Found This Useful (0 Votes)