cPanel Tutorial – How to Manually Edit .htaccess File

.htaccess file is a directory-level text file, that allows for decentralized management of Apache web server configuration without direct root access to the physical server. .htaccess stands for ‘Hypertext Access’. This file can be modified to override the server’s global configuration settings. It is often used to set up URL rewrite rules and/or to specify security access restrictions for a directory on your hosting account.

cpanel-.htaccess-file-edit

The intent of this tutorial is to walk you through the process of editing .htaccess file manually via cPanel’s File Manager tool.

Please keep it in mind that .htaccess file can automatically be modified by your hosting control panel (cPanel, Plesk) while creating domain redirect rules or modifying your php.ini file. Few CMS scripts can also automatically update .htaccess file; for example – .htaccess file gets modified when you make any changes to permalink structure in your WordPress admin dashboard. So, don’t be surprised to see a few line of code in your .htaccess file when you are accessing it for the first time using a file manager tool.

STEP 1: To make modifications to .htaccess file, you would first need to browse to the directory where the file is stored. We will be using cPanel’s ‘File Manager’ tool for this. Log in to your cPanel interface. Scroll down to ‘Files’ section and click on ‘File Manager’ icon.

STEP-2: A new window will pop up prompting you to select the directory you would like to browse. Select the second radio button ‘Web Root’, which is the base directory for your publicly-available website. Mark the checkbox adjacent to ‘Show Hidden Files (dotfiles)’ and click on the ‘Go’ button.

STEP-3: In the File Manager interface, the left pane holds the directory structure, while the files inside the selected directory are listed on the right pane. Look out for the file named ‘.htaccess’ on the right pane.

STEP-4: It is always suggested to keep a backup of your current .htaccess file before attempting to edit the codes/rules. It will help you to restore your previous configuration settings if something goes wrong with your .htaccess experiment. To take a backup, simply select the file and click on the ‘Copy’ button available on top of your File Manager menu.

STEP-5: A dialog box will prompt you to specify a file name for the backup file. Once you have specified a new file name, for example ‘.htaccess_backup’, click on the ‘Copy File(s)’ button that can be located at the bottom of the dialog box.

STEP-6: Now we are ready to edit the .htaccess file. Select the file and click on either “Edit” or “Code Editor” button in your File Manager’s tools menu.

STEP-7: Edit the required code in “Code Editor” interface. For example, if you would like to direct the non-www version of your website to the www version, you can place the following code in your .htaccess file –

RewriteEngine On
RewriteCond %{HTTP_HOST} ^yourdomainname.com
RewriteRule (.*) http://www.yourdomain.com/$1 [R=301,L]

STEP-8: When you are done with editing, click on the ‘Save Changes’ button in the top right corner. Click on the ‘X’ button to close your code editor window and return to the file manager interface.

With this you have learned how to manually edit .htaccess file using the File Manager tool in cPanel hosting interface.

Leave a Reply