Many customers at some point request to force either the www or non-www version of their site to display in their visitor's browser. For example always have or simply display in their visitor's web browser. There is a common thought that forcing one format is better for search engine optimization. This article will guide you through how to perform this action in your .htaccess in the cPanel for your primary domain.

How to force www or non-www in your .htaccess file in cPanel

  1. Log into your cPanel
  2. Find the Files category and click on the File Manager icon.
  3. A popup box will appear. For the primary domain, click on the Web Root radio button. For addon domains, click on the dropdown and find your desired addon domain name. Be sure the checkbox next to Show Hidden Files is checked. Click the Go button to enter the File Manager.
  4. You should now be in the root folder of the domain you chose. Look for the .htaccess file and right click on it. This brings up a menu. Find and click on the Edit option. If you get a popup box, simply find and click the Edit button in the lower right corner to continue to the editor.
  5. You are now in the text editor. Place either selection of code in the file and click on the Save Changes button at the top right corner of the screen. Be sure to replace '' with your actual domain name. NOTE: do not place both selections of code in the file as it will cause an error.
    #Force www:
    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^ [NC]
    RewriteRule ^(.*)$$1 [L,R=301,NC]

    #Force non-www:
    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^www\.example\.com [NC]
    RewriteRule ^(.*)$$1 [L,R=301]
  6. Now, when you type in your domain name with either www in front or not, it should display as you have set it in the .htaccess file.
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

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

Support Center Login

Social Media Login

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!
Ask a Question
n/a Points
2014-06-12 2:40 pm

Thank you so much, Scott!


My website, was facing canonicalisation issue, couldn't find how to fix it until a solution from a source i came across. it suggested me to fix .htaccess and upon searching on Google, i found your site. (The site still has a lot of SEO-issues)

Thank you for having such a great explantory note.



Pawan Kr Jha

n/a Points
2014-09-01 4:45 am
Explain how to enable cpanel to show the .htaccess file, which isn't showing in my one.
13,750 Points
2014-09-18 9:41 am
Hello Rob,

Thank you for contacting us. Please see our guide Where is my .htaccess file?

It includes how to find your .htaccess file, and how to create one if it is not there.

If you have any further questions, feel free to post them below.

Thank you,
n/a Points
2014-10-20 4:31 pm

Great job, There are another tutorial about .htaccess, it provides some useful examples,

13,750 Points
2014-11-28 12:58 pm

Thank you for your suggestion. Feel free to submit a post in our User Submitted section. I can then link to your post.

You can then list yourself as a Contributor to the Support Center.

Thank you,
n/a Points
2014-10-22 4:55 am

Thank You very much for your 3lines codes, it helps me a lot.

n/a Points
2014-10-22 5:00 am
I am new to htAccessm if you can tell us whats NC, L... stands for what then it will be very helpful to understand.
23,981 Points
2014-10-22 7:45 am
Hello Dhirender,

The NC means 'no-case', or case insensitive. It means it does not matter if uppercase or lowercase is used.
The L means 'last'. When it runs across this, the process should stop where it is and not apply any more rewrite rules.

Kindest Regards,
Scott M
n/a Points
2014-10-22 8:00 am
Great :)
2014-11-28 2:35 am
Hello IMH. I'm a IMH subscriber.

I can no longer access a subdomain, say, after forcing to in .htaccess file. Please how do I resolve this? I prefer to display the subdomain as instead of Thank you.
13,750 Points
2014-11-28 1:00 pm
Hello Ndiana,

Thank you for contacting us. There may be an existing rule interfering with the ones you are adding from this article. I recommend reviewing the existing rules for incompatibility issues.

Also, it may be easier to make this change in your CMS, for example are you using WordPress, Joomla, or Drupal?

Renaming your .htaccess file (such as .htaccess.old) should allow you to regain access to your site.

Thank you,
n/a Points
2015-01-14 1:21 am

my website is not opening in mobile devices it redirect in please help me what can i do.


23,981 Points
2015-01-15 11:29 am
Hello Rahul,

This article is only about forcing www or non-www redirects, not specific redirect issues. I have moved your comment to be a new question here. You will want to start a new question in the future.

Kindest Regards,
Scott M
n/a Points
2015-01-30 7:30 am
You are the best. I resolve my problem. Thank you very much.
n/a Points
2015-02-24 8:30 am



How to redirect: to

I can do this for http but not for https.


Thank you,



13,750 Points
2015-02-24 9:41 am
Hello hassan,

Thank you for your question. Most likely an existing .htaccess rule is interfering with the one you are adding.

If you are using a CMS (such as WordPress, Joomla, Drupal, or Concrete5); you may have to change the URL in the config file, or use a plugin/extension.

Thank you,
n/a Points
2015-03-14 5:25 pm
My website redirects non-www http:// to https:// but with a www it simply stays at http:// and I just cannot find a way to do both.
13,750 Points
2015-03-26 9:29 am
Hllo Justo,

Thank you for contacting us. If the redirect rules are not working, most likely an existing rule is interfering, or you have to make the change in your CMS.

Are you using a CMS, such as WordPress, Drupal, or Joomla? If so, you will have to update the site URL in the settings/Admin dashboard.

Thank you,
n/a Points
2015-03-25 11:10 am
We'll all have to make the transition to https before long. I'll need a guide for that as there will be four domains then : ; ; ;
n/a Points
2015-03-26 3:51 am

Hi Jon,

Your input is fine for forcing non-www to www.

How about redirecting all http://example, https://example to

13,750 Points
2015-03-26 9:43 am
Hello Jason,

Thank you for your question. Please see our guide Forcing your Website's visitors to use the shared SSL. Instead of redirecting to the shared SSL, force your SSL site, such as

If you are using a CMS, you will most likely have to update the site URL in the settings/Admin dashboard.

Thank you,
n/a Points
2015-03-26 5:15 pm

Hi Jon, 

I am using Joomla and I moved all my web files from another host as your hosting was recommended still I can't make .htaccess work properly with Joomla I want friendly urls now I had to disable it so website works coz when I enable friendly urls all links are broken and it shows 404 msg can you please help? 

23,981 Points
2015-03-27 10:45 am
Hello rei,

Have you checked the htaccess to see if you need to remove any residual redirects before resetting the SEO friendly URLs?

Kindest Regards,
Scott M

Post a Comment

Email Address:
Phone Number:

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

23 Questions & Comments

Post a comment

Back to first comment | top

Need more Help?


Ask the Community!

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

Current Customers

Chat: Click to Chat Now E-mail:
Call: 888-321-HOST (4678) Ticket: Submit a Support Ticket

Not a Customer?

Get web hosting from a company that is here to help. Sign up today!