The .htaccess file in your account is a plain text file that provides a way to make configuration changes to your website.
What can I modify in the .htaccess file?
The .htaccess file can be used to complete different advanced functions on your website, including:
- Making changes to your local PHP settings. If you have to modify the php.ini file, then you will need to add the suPHP_ConfigPath to your .htaccess file.
- Remove Hacks. If your website is ever hacked, sometimes the hacker simply adds a few lines of code to your .htaccess file. This is generally the easiest type of hack to remove as the hack codes are generally clear. If you think you have a hacked code in your .htaccess file our technical support team would be happy to assist you.
- Create redirects. If you need to create a redirect that you are not able to create in your cPanel, then the redirect can be added directly in your .htaccess file.
The .htaccess file is modified automatically by different cPanel features (such as creating a domain re-direct) and by many software programs such as WordPress, so if you open your .htaccess file and there is already code in there that is perfectly normal.
How do I access and edit my .htaccess file?
In this example we will walk through how to manually edit the .htaccess file to redirect the non-www version of our site to the corresponding www version of our site or vice versa (redirect www to non-www). This can usually be done through the cPanel, but if you're having any trouble creating the redirect in cPanel, you can easily edit your .htaccess file to set this up.
- Start by logging into your cPanel.
- Click on the File Manager icon under the Files area on the cPanel home page.
- Select the document root for the domain you want to edit the .htaccess file for.
- Make sure you select the option for Show Hidden Files (dotfiles).
- In the cPanel File Manager select the .htaccess file and make a copy of it by selecting Copy in the File Manager menu.
- In the dialog window that appears, type in the name you want for your .htaccess backup and click the Copy File(s) button. In this example, we are naming the file .htaccess_bk
- This will create a backup of your .htaccess file
- Now we are readty to open the .htaccess file editing. Click on the .htaccess file and select either Edit or Code Editor in the File Manager menu.
- If I want to direct the non-www version of example.com to the www version I would place the following code into my .htaccess file:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example.com
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
- Conversely, if I want to direct the www version of example.com to the non-www version, I would enter the following code into my .htaccess file:
RewriteEngine on
Options +FollowSymLinks
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]
- Once your edits to the .htaccess file are complete, click on the Save Changes button in the upper right of the page and then click the Close button to close the file and return to the File Manager.
We value your feedback!
There is a step or detail missing from the instructions.
The information is incorrect or out-of-date.
It does not resolve the question/problem I have.
new! - Enter your name and email address above and we will post your feedback in the comments on this page!