InMotion Hosting Support Center

Sometimes it's necessary to make sure your website’s visitors use the SSL encrypted connection. If you’re not familiar with SSL and would like to know more please review our article “What is SSL and Why is it important?” If you need assistance using the shared SSL that InMotion Hosting offers to shared hosting customers, please see our article on "forcing your visitors to use the shared ssl". Click here to learn more about Dedicated Hosting.

Forcing visitors to use SSL can be accomplished through your .htaccess file using mod_rewrite. If you’d like more information on mod_rewrite please read our article.

If you are using the Premium Website Builder and need to force your website traffic over SSL, please see the following article instead:
How to force your Premium Website Builder website over SSL

To force all web traffic to use HTTPS insert the following lines of code in the .htaccess file in your website’s root folder.

Important:If you have existing code in your .htacess, add this above where there are already rules with a similar starting prefix.

RewriteEngine On 
RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]

Be sure to replace www.example.com with your actual domain name.

To force a specific domain to use HTTPS, use the following lines of code in the .htaccess file in your website's root folder:

RewriteEngine On 
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]

Make sure to replace example\.com with the domain name you're trying force to https. Additionally, you need to replace www.example.com with your actual domain name.

If you want to force SSL on a specific folder you can insert the code below into a .htaccess file placed in that specific folder:

RewriteEngine On 
RewriteCond %{SERVER_PORT} 80 
RewriteCond %{REQUEST_URI} folder 
RewriteRule ^(.*)$ https://www.example.com/folder/$1 [R,L]

Make sure you change the folder reference to the actual folder name. Then be sure to replace www.example.com/folder with your actual domain name and folder you want to force the SSL on.

If you need further assistance please feel free to ask a question on our support center website.

Support Center Login

Social Media Login

   
Social Login Joomla

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
2015-12-30 9:16 pm

Hi

I would like to interesting how can I set just 1 or 2 pages?

sample : xxx.com/cart  and xxx.com/checkout

 

thank you

victor

Staff
34,766 Points
2015-12-31 10:38 am
Hello Victor,

Your SSL would still need to be for the domain, but then the code would be exactly the tutorial displays above for the folders:

RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} folder
RewriteRule ^(.*)$ https://www.yourdomain.com/folder/$1 [R,L]


If you have any further questions or comments, please let us know.

Regards,
Arnel C.
n/a Points
2016-01-20 1:13 pm

Thanks, nice somple howto.

n/a Points
2016-02-18 2:46 pm

Is there a way to force SSL on a single post in wordpress via the .htaccess codes above? Thanks!

Staff
25,021 Points
2016-02-18 6:52 pm
Hello Joe,

Thank you for contacting us. Since you are using WordPress (which also relies on .htaccess rules), I recommend using a plugin instead of adding a .htaccess rule directly.

This is to avoid a rule interfering with the functionality of your website.

Thank you,
John-Paul
n/a Points
2016-04-01 9:03 am

when i add the above code the site going down .

thanks

Staff
25,021 Points
2016-05-09 10:49 am
Hello faiz,

Thank you for contacting us. If you are using a CMS (such as WordPress, Joomla, Drupal, etc.) I recommend using a Plugin, or module to avoid conflicts.

Are you getting any error messages?

Best Regards,
John-Paul
n/a Points
2016-04-19 10:15 pm

This is the coding I had in my .htaccess file:

##### RewriteEngine enabled - BEGINRewriteEngine On##### RewriteEngine enabled - ENDRewriteCond %{HTTP_HOST} ^mydomainname\.com [NC]RewriteCond %{SERVER_PORT} 80 RewriteRule ^(.*)$ https://www.mydomainname.com/$1 [R,L]And this is what was displayed in the browser window:

"An error occurred during a connection to www.mydomainname.com. SSL received a record that exceeded the maximum permissible length. Error code: SSL_ERROR_RX_RECORD_TOO_LONG"

 

Of course I substituted mydomainname with the name of my domain.

Please advise.

Staff
39,585 Points
2016-04-20 9:28 am
Hello Jim,

The error message indicates that the redirect is working as it is an SSL error message. You will want to check the SSL itself to make sure it is a) setup at all and b) set up correctly.

Kindest Regards,
Scott M
n/a Points
2016-05-09 5:41 am

Hi,

my host is Siteground and the it wrote me this code that write in htaccess

RewriteEngine On RewriteCond %{SERVER_PORT} 80 RewriteRule ^(.*)$ https://www.sergiopinna.it/$1 [R,L]

 

And it works perfect.

n/a Points
2016-05-09 8:26 am

This approach is better, automatically gets your URI:

===================================

RewriteEngine On

RewriteCond %{HTTPS} off

RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

n/a Points
2016-05-11 9:19 pm

Yes it did perfectly worked for me.... Thanks a lot .... I was after this solution for about two days....

n/a Points
2016-05-25 4:14 am

Hi,

I want to redirect url without www to https://www using .htaccess or any. Please support me . It' s urgent.

Thanks.

Staff
34,766 Points
2016-05-25 7:14 am
Hello Rajesh,

Thanks for the question about redirecting without using WWW in the URL. Your question is a little confusing because you use "www" in the HTTPS url that you indicate. However, you can use the tutorial above by simply changing the rewrite to rewrite to the https:// with no WWW in the URL. The condition for the change would indicate the WWW version of the URL.

I hope this helps to answer your question, please let us know if you require any further assistance.

Regards,
Arnel C.
n/a Points
2016-06-25 9:43 am

As I just mentioned above.... this will solve all of your issues and automtically add www. if your domain is set up that way.

In your .htaccess, add:

RewriteEngine On

RewriteCond %{HTTPS} off

RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

n/a Points
2016-05-27 4:05 pm

What about domains that don't use "www". Actually, I need ssl for both the "www" and the non-www versions of my site.

Should I add anything more to the code?

Staff
10,077 Points
2016-05-28 12:08 am
Hello Steve,

You should not have to add anything as long as your SSL is setup for the www version and non-www version.

Best Regards,
TJ Edens
n/a Points
2016-05-28 8:00 am

Hi,

My website has minor problem only home page doesnt redirect to https but all other pages does redirects to https.

If I click on any other page and then go back to home page then it stays on https. can you please help.

below is the code in my .htaccess file

 

# BEGIN WordPress

<IfModule mod_rewrite.c>

RewriteEngine On

RewriteRule ^(.*)$ https://www.e-astrologer.com/$1 [L,R=301,NC]

RewriteBase /astro/

RewriteRule ^index\.php$ - [L]

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule . /astro/index.php [L]

</IfModule>

 

# END WordPress

Staff
39,585 Points
2016-05-31 9:18 am
I see your site is a WordPress site. Did you set the Home and Site URLs to use HTTPS?
n/a Points
2016-05-28 12:33 pm

I have...wild card SSL

1. wildcard SSL for site xyz.com

2. hosted wordpress on subdomain abc.xyz.com

but when I enable https on wordpress abc.xyz.com from General Settings (dashboard) and access the https://abc.xyz.com it redirects to https://xyz.com 

Could you please help

 

Thanks

Staff
39,585 Points
2016-05-31 9:20 am
You may want to try a more generic code like the one below:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
n/a Points
2016-05-30 2:29 am

Please clear me that how your code is different from below code (Jake mentioned too). What are the implications of using your code and below code?

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Thanks!

Staff
39,585 Points
2016-05-31 9:20 am
Our code is just one way to force the https. Glancing at the code you have, it appears it may do the same thing. You can use whichever one works best for you.
n/a Points
2016-06-08 4:15 am

Hello!Thank you for that, quite simple.But, if I try to access "domain.com/folder/page", works perfectly. But if I try with the prefix "www.domain.com/folder/page", my browser say it's an insecure connection.Would you have any hints on that?Thank's!

Staff
10,077 Points
2016-06-08 6:28 am
Hello Lucas,

Have you checked your pages source code to check what content is not being loaded via https://?

Best Regards,
TJ Edens
n/a Points
2016-06-09 2:59 am
Hello i have the following error https://www.*****.co.za " when i place this code
 
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.isolarsolutions.co.za/$1 [R,L]
 
if i try to access my admin  i get the error below
 

Not Found

The requested URL /wp-admin/ was not found on this server.

Apache Server at ******.co.za Port 443
 
The website is made from wordpress
 
Thanks
Staff
25,021 Points
2016-06-09 1:35 pm
Since you are using WordPress (which relies on .htaccess rules), manually adding rules can cause issues.

Instead, I recommend forcing https in WordPress. This is covered in our full article How to Enable https (SSL) in WordPress.

Thank you,
John-Paul
n/a Points
2016-06-29 6:23 pm

Over the past month I have installed five SSLs on five sites. And this htaccess code has not worked on one. Not one. (All are WordPress sites.)

I had to trouble shoot each site and each site had a different solution.

I don't want to hashout what did and didn't work here. I could really care less. (Really, it is too frustrating.)

But I DID FIND A WAY THAT SEEMS TO WORK FOR WordPress. I just installed a sixth SSL. Instead of all the plugin/htaccess mess I just went into phpmyadmin and changed the site URL and home URL from http://mysite.com to https://mysite.com.

This appears to have done the trick. Is there anything wrong with doing this?

Thanks.

Staff
34,766 Points
2016-06-29 7:14 pm
Hello Steve,

The method you used is what was needed to enable SSLs for WordPress. We have a tutorial for WordPress HTTPS here. If you have any further questions, please let us know.

Kindest regards,
Arnel C.
n/a Points
2016-07-04 11:00 am

Why not use Server Name parameter ? this way you can copy and paste it to all the website's you need. Or even put it as a global rule for apache.

 

RewriteCond     %{SERVER_PORT} ^80$RewriteRule     ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R]

 

n/a Points
2016-07-06 9:28 am

How would you exclude certain paths? Some Magento extensions do not work well with forced SSL in the admin area. Thanks in advance! 

Staff
34,766 Points
2016-07-07 6:35 am
Hello Alex,

We don't really have a tutorial about that ourselves, but you can find regular expression tutorials through search that discuss it. Here's one that may help.

If you have any further questions, please let us know.

Kindest regards,
Arnel C.
n/a Points
2016-07-28 3:18 pm

This does not work. I have some pages that go to https and other that go to http. After hours with inmotion hosting they told me that I have to hard all my web pages, which is silly and I am confident is wrong. I mean why use this in that case? Maybe they should have qualified the statement that this will only work if you hard code it, whatever that means. So I hard coded (meaning put https to all the links) some of the pages to test their theory and what they say does not work. I suspect the SSL has been badly configured by inmotion which make mistakes like the time i asked for TLS 1.2 and they said they do not offer it. But after pushing them for a while I discovered they do indeed offer it in upgraded server. This is why proper training and knowledge is important.

Staff
25,021 Points
2016-07-28 4:37 pm
Hello Asela,

Thank you for contacting us. Sorry to hear you are having issues forcing https on your website. I first checked your SSL with an SSL Checker tool, and it is installed correctly. Since we now know the SSL is not badly configured, we can rule this out.

TLS 1.2 has been available on our shared servers since December 2015, it was available on VPS/Dedicated servers before since you have the ability to change your server settings. If you asked for TLS 1.2 on shared servers prior to December 2015, it may not have been available yet.

When I test your site, the example.com redirects to https://www.example.com, which seems to be correct. But, when I check the links in your site menu, many are pointing to http URL's instead of https. For example:
Home, all of the products (such as Tea, Powder, etc.), all of the "Benefits" links, Blog, and Cart.

So, while it may force SSL on the main domain, these links seem to navigate visitors back to http (non SSL) pages.

Also, for a page to be secure, everything being called on the page must be from an https address. When I reviewed your site, many files are being called in insecurely. You can view these by reviewing your site on whynopadlock.com, which is a free tool.

If you suspect the redirect rules are not working, I recommend reviewing the other rules in the .htaccess file as one may be interfering. You can also troubleshoot the .htaccess by renaming it, for example to .htaccess.old

Thank you,
John-Paul
n/a Points
2016-07-29 3:11 pm

Hello John-Paul,

Thanks for that well thought out reply. Whynpadlock was very useful to test. Thank you. The TLS 1.2 I had requested this year, so be aware some of your reps don't have perfect knowledge. Of course what this shows is that forcing into https does not alwasy work. At the end of the day you have to hard code all the links.

But I appreciate your reply which has improved my confidence in inmrtion hosting. Thank you.

n/a Points
2016-07-29 7:52 pm

Just installed SSl on my domain. To force all web traffic to use SSL, Where do i add this code:

RewriteEngine On 
RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]My current htaccess looks like like this...# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Staff
25,021 Points
2016-08-01 10:55 am
WordPress relies on .htaccess rules, which can cause issues when you add code directly to your .htaccess file as described in the guide above.

Since it seems you are using WordPress, you should enable HTTPS (SSL) in WordPress.

Thank you,
John-Paul
n/a Points
2016-08-04 8:13 am

Hi, I want to redirect http to https only for home page not all other pages.Please advise me.

Thanks 

Staff
25,021 Points
2016-08-04 4:00 pm
Here is a link to an online post I found via search engine, where they discuss possible solutions.

Thank you,
John-Paul
n/a Points
2016-08-05 7:10 am

Hi

i have a problem with my 301 redirects. I have 1 going from non www to www and http to https.  So far so good. If I go non https version of home page either www or non www it directs to https://www as it should. It go to the non https of a page it doesn't redirect. 

Staff
5,440 Points
2016-08-05 7:42 am
I advise commenting out other rules to see if they might be having an affect on the rewrite rules.
n/a Points
2016-08-09 3:27 pm

You should change the code to R=301 so it becomes a 301 redirect. This will preserve people's backlinks and rankings in google. 

 

RewriteEngine On 
RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]
n/a Points
2016-08-11 4:51 am

Hi, i want to force https for my subdomain, where do i need to place above code? it is in root or htaccess in subdomain folder? i have try both, but didn't work. When i place this code my page cannot be open and dislay this

This site can’t be reached

 

www.XXX.com’s server DNS address could not be found.

Staff
25,021 Points
2016-08-11 11:24 am
Typically, you would put it in the document root of your subdomain.

Keep in mind if you are using a CMS (such as WordPress, Joomla, Drupal, etc.) that they also rely on .htaccess redirect rules, and we recommend changing the setting in the dashboard instead of forcing it directly in the .htaccess file.

Thank you,
John-Paul
n/a Points
2016-08-13 7:25 pm

Great tutorial.

Work perfect on website.

RewriteEngine On 
RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]

 

n/a Points
2016-08-14 4:30 pm

iam usin this code

RewriteEngine On RewriteCond %{SERVER_PORT} 80 RewriteRule ^(.*)$ https://mydomin.com/$1 [R,L]

and when i go to my domain this message appear

The domain.com page isn’t working

domain.com redirected you too many times.

 

 

can u help me on that please

Staff
11,563 Points
2016-08-15 8:43 am
What is your actual domain name?
n/a Points
2016-08-15 10:30 am

this is my domain name

****.com

****.com/xf

and i removed the htaccess for ***.com

Staff
39,585 Points
2016-08-15 3:26 pm
The code below should work fine:
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]

You can also try:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]

Be sure it is up at the top of your .htaccess file.

Kindest Regards,
Scott M
n/a Points
2016-08-20 10:30 am

in first "example.com" you need to replace it with your full domain like this www.example.com in this way it worked for me.

n/a Points
2016-08-24 10:59 am

I have a blog installed in a subdirectory with no SSL.

In the root directory we have another WordPress installation which is membership based and has SSL.

Sometimes the blog switch over to HTTPS and the blog's CSS goes missing.

 

Is there a way to reverse this, i.e. force the blog to display http:// instead of https:// ?

 

Thanks

Torkild

Staff
34,766 Points
2016-08-24 11:04 am
Hello Torkild,

You can use the last code provided in the tutorial above and change it to use HTTP instead of HTTPS.

If you have any further questions or comments, please let us know.

Regards,
Arnel C.
n/a Points
2016-09-04 8:45 am

If I use this in my .htaccess it tells me either that the page doesn't work because it redirected me too many times or it gives me an internal server error

Staff
5,440 Points
2016-09-06 12:28 pm
It's possible the file may be conflicting with rules in another .htaccess file in the same directory or nested elsewhere.
Staff
34,766 Points
2016-09-08 8:20 am
Hello Joshua,

Thanks for the question about forcing the SSL on your other pages. You should first make sure to follow the tutorial above. You should also go to any links that reference your other pages and make sure that they are using HTTPS. The re-write rule above should work for any domain or subdomain that has been covered by the SSL certificate. However, if you intend to keep all of your pages to use SSL, then your page links should using the SSL link and not HTTP.

I hope this helps to answer your question, please let us know if you require any further assistance.

Regards,
Arnel C.
n/a Points
2016-09-09 2:06 pm

Hey!

I used your code for my website ans when I open it in the browser it shows me: ERR_TOO_MANY_REDIRECTS

Staff
5,440 Points
2016-09-09 2:25 pm
It is possible there are other .htaccess files that are affecting each other. I advise checking your Home directory.
n/a Points
2016-09-09 6:00 pm
Please help me. After installing latest SSL in my website, i found out that old browsers can not access my website, though i have added this(RewriteEngine On RewriteCond %{HTTPS} !=on RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L] ) to force my site to https. So since because of that old browser issue, i want to make only my index.php page to beecome http so that i can notify my users to upgrade there browser before going to another page. please i need help.
Staff
5,440 Points
2016-09-09 6:23 pm
You can redirect https to a specific folder you would like to secure, like "example.com/store" or "/secure", following the final steps of the article above. Use the code from the last example.
n/a Points
2016-09-14 4:27 am

I installed SSL on my domain and changed http to https.now what my problem is if i want to view a page with http://mydomain.name/page.html it redirects to homepage.but https://mydomain.name/page.html means it shows correctly

Staff
34,766 Points
2016-09-14 3:18 pm
Hello Akilan,

If your linkings are FORCING you to go to HTTPS, then HTTP may not be available. Make sure that your links are not forcing you to use HTTPS, then you should be able to use the non-HTTPS urls to access your site. Re-directs are found within the .htaccess file. Check this file to see if you have any re-directs/re-write rules that are affecting how you get to your HTTP URL.

If you have any further questions or comments, please let us know.

Regards,
Arnel C.
n/a Points
2016-09-15 2:07 pm

Hi I too need a force SSL option on my website via .htaccess. What will I need to redirect all http pages/posts to their https counterparts using a 301 redirect? I would like to pass the "link juice" along to the https version so it isn't lost. Thanks.

Staff
25,021 Points
2016-09-15 2:28 pm
Google should not penalize you for using 301 redirects to redirect your traffic.

Here is a helpful link to the Google guide on how to Change page URLs with 301 redirects for more information.

Thank you,
John-Paul
2016-09-16 11:39 am
Working prefect for my domain: jodyshop.com
Thank you
n/a Points
2016-09-18 10:46 am

Wow! It works! YES... so easy, so simple. Thank you... Finally SSL without errors

  • domain.com to https://www.domain.com
  • www.domain.com to https://www.domain.com
  • https://domain.com to https://www.domain.com
  • domain.com/file.jpg to https://www.domain.com/file.jpg

 

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.

66 Questions & Comments

Post a comment

Back to first comment | top

Need more Help?

Search

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: support@InMotionHosting.com
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!