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.

  1. Start by logging into your cPanel.
  2. Click on the File Manager icon under the Files area on the cPanel home page.
  3. Select the document root for the domain you want to edit the .htaccess file for.
  4. Make sure you select the option for Show Hidden Files (dotfiles).

    cpanel-file-manager-show-hidden-files

  5. In the cPanel File Manager select the .htaccess file and make a copy of it by selecting Copy in the File Manager menu.

    copy-htaccess

  6. 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

    copying-htaccess

  7. This will create a backup of your .htaccess file

    htaccess-copied

  8. 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.

    cpanel-file-manager-htaccess-edit

  9. 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]

  10. 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]

  11. 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.
Did you find this article helpful?

We value your feedback!

Why was this article not helpful? (Check all that apply)
The article is too difficult or too technical to follow.
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.
How did you find this article?
Please tell us how we can improve this article:
Email Address
Name

new! - Enter your name and email address above and we will post your feedback in the comments on this page!

Did you find this article helpful?

Post a Comment

Name:
Email Address:
Phone Number:
Comment:
Submit

Please note: Your name and comment will be displayed, but we will not show your email address.

Related Questions

Here are a few questions related to this article that our customers have asked:
Ooops! It looks like there are no questions about this page.
Would you like to ask a question about this page? If so, click the button below!
Need More Help?

Help Center Search

Current Customers

Email: support@WebHostingHub.com Ticket: Submit a Support Ticket
Call: 877-595-4HUB (4482)
757-416-6627 (Intl.)
Chat: Click To Chat Now

Ask the Community

Get help with your questions from our community of like-minded hosting users and Web Hosting Hub Staff.

Not a Customer?

Get web hosting from a company that is here to help.
}