How to edit .htaccess and other hidden files in cPanel

Published Updated

To edit .htaccess in cPanel, open File Manager, click Settings, select Show Hidden Files (dotfiles) and click Save. The file then appears in public_html.

File Manager hides dotfiles by default. Dotfiles are files whose names start with a dot, such as .htaccess, .env and .user.ini. They stay hidden until you turn on hidden files in the File Manager settings. File Manager lets you edit them in your browser, without the command line (SSH).

Before you begin

  • You need access to cPanel. See What is cPanel and how do I log in?
  • Make a copy of any file before you change it. One wrong line in .htaccess can take your whole website offline.

Show hidden files in cPanel File Manager

  1. Log in to the 2MHost client area at www.2mhost.com/login.
  2. Go to Hosting accounts and click the cPanel button of your hosting account. cPanel opens already signed in.
  3. In the Files section, click File Manager. File Manager opens in a new tab.

cPanel Files section with the File Manager icon

  1. Click Settings in the top-right corner of File Manager.
  2. Select Show Hidden Files (dotfiles).
  3. Click Save. File Manager now shows all files whose names start with a dot.

cPanel File Manager Preferences window with Show Hidden Files (dotfiles) selected

Edit the .htaccess file in File Manager

In cPanel File Manager, with hidden files turned on:

  1. Double-click the public_html folder in the left panel or the file list. The .htaccess file of your main domain is in this folder.
  2. Right-click .htaccess and click Copy. Enter a new name such as public_html/.htaccess.bak and confirm. This is your backup.
  3. Right-click .htaccess and click Edit.
  4. If a window about character encoding appears, click Edit again. The file opens in the text editor.
  5. Make your changes.
  6. Click Save Changes. The change applies right away.
  7. Open your website in a browser and check that it still loads.

You edit any other hidden file, such as .user.ini or .env, the same way. For PHP settings in .user.ini, see How to modify PHP variables like memory_limit?

Note: An addon domain or subdomain usually has its own folder, with its own .htaccess. Open that folder instead of public_html to change the settings of that site.

Create a .htaccess file if it does not exist

Some websites have no .htaccess file yet. In cPanel File Manager:

  1. Open the folder of your website, for example public_html.
  2. Click + File in the toolbar.
  3. Enter .htaccess as the file name, with the dot at the start.
  4. Click Create New File. The empty file appears in the list, ready to edit.

Troubleshooting

500 Internal Server Error after saving .htaccess

The file most likely has a typing error or a rule the server does not support.

  1. In cPanel File Manager, open the folder that holds the file.
  2. Delete or rename the edited .htaccess.
  3. Rename your backup, such as .htaccess.bak, back to .htaccess. Your website loads again.

.htaccess does not appear in public_html

Either hidden files are still off, or the file does not exist.

  1. In File Manager, click Settings and check that Show Hidden Files (dotfiles) is selected.
  2. Click Reload in the toolbar to refresh the file list.
  3. If the file is still missing, create it as described in Create a .htaccess file if it does not exist.

Frequently asked questions

Does showing hidden files change my website?

No. The setting only changes what File Manager shows you. Visitors and your website are not affected.

What can I do with a .htaccess file?

You can redirect visitors, force HTTPS, block access and change some server settings for one folder. For example, see Load website using SSL (HTTPs) by default.

Related articles