InMotion Hosting Support Center

Many times, it is beneficial or even necessary to make sure your website's visitors are accessing your site using an SSL-encrypted connection, whether for security, accessibility, or PCI compliance reasons. If you’re unfamiliar with SSL and would like to know more, please review our article What is SSL and why is it important? for more information.

InMotion Hosting includes a free SSL Certificate by default for all Business Class Hosting Plans. This SSL can be activated with a simple switch in your Account Management Panel (AMP) under My Account > Manage Free SSL.

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.

Forcing HTTPS with .htaccess

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

Our Login page has moved, Click the button below to be taken to the login page.

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
39,923 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
29,997 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
29,997 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
43,761 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-09-23 7:30 pm

brilliant!!!  this the most simple solution I've seen.  Any advice as to how search engines will look at this?

n/a Points
2016-12-28 5:55 pm

htconfig files exicute server-side, then send the "final-product" to the client; so, Search Engines will index the final URI.  So if your htaccess says your home page is https://mysite.com, then it is so.  The caviot is that if you write an internal link to http://mysite.com and Google ends up at https://mysite.com then it will be aware that it was redirected; so, you must be careful about how you handle it.

Generally, search engines don't care about protocol redirects, but if you use your htaccess file to redirect to a new domain, such as http://mysite.com to http://anothersite.com, expect to get flaged.

Lastly, if you want to use it to redirect between internal pages where you want to change your URL, but keep all of your SEO goodness that has already been indexed, such as http://mysite.com/wordpress to http://mysite.com/blog, make sure to use a 301 or 302 redirect.

n/a Points
2017-02-12 11:56 pm

add [R=301,L] to the end of the last line; it's sets the redirect to Permanent (for Google and/or for my mom--cuz I moved out of her bsmt for good.)

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
39,923 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
2017-03-13 7:53 pm

This code does NOT add www.

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
43,761 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
43,761 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
43,761 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
29,997 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
39,923 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
39,923 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
29,997 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
29,997 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
29,997 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
9,669 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]
2017-04-25 3:13 pm
This is better than the 302 redirect IMH example provides. I tested this in SEO Powersuite and they did not like the version without the 301 which seems correct.

I would change this Inmotion to the example with the 301 in it.

Thanks for the help though.
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
29,997 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
13,701 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
43,761 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
39,923 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
9,669 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
39,923 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
9,669 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
9,669 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
39,923 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
29,997 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

 

n/a Points
2016-09-28 9:46 am

How can I install it in a subdomain

Staff
39,923 Points
2016-09-28 11:31 am
Hello Daniel,

You simply need to add the subdomain into the URL in the rule. This is not an "installation".

For example:

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-10-06 8:06 am

Hello,

I have many pages that I would like to redirect to a new domain in a htts://www. version of my website. Could you please tell me the .htaccess code for each one of them? 

conditions :

if http://www.example.co.uk/page1 

or http://example.co.uk/page1

or https://www.example.co.uk/page1

or https://example.co.uk/page1

redirect (301) to

https://www.example.com/page1

 

----Your reply with the code will be used many times, for each one of these pages (page1, page2, page3 etc)

Thanks in advance

Staff
29,997 Points
2016-10-06 9:50 am
Hello Andreas,

Thank you for contacting us. We do not provide custom solutions, but you should be able to accomplish this by adjusting the examples above.

Thank you,
John-Paul
n/a Points
2016-10-13 4:26 am

Hi I want to remove the folder name from URL access. How to achieve that?

Staff
39,923 Points
2016-10-13 10:19 am
Hello Vinoth,

You would need to use a Rewrite rule. This will rewrite the URL so that they see only what you want them to see.

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

Regards,
Arnel C.
n/a Points
2016-10-20 1:50 pm

So i have ssl on a .co domain name and i also have a http .com domain that redirects to the https .co domain, if someone should put the https infront the .com domain, it will give a security error, anyway to fix or adjust that?

 

Howard

Staff
29,997 Points
2016-10-20 5:12 pm
The easiest way to fix this is to install an ssl for the .com domain.

Thank you,
John-Paul
n/a Points
2016-10-27 6:45 am

Hi,I want to redirect  https://www.example.com/notice  to ( my another server )https://info.example.com/noticeBoth have SSL installed, https://www.example.com is wordpress site.what should i write to .htaccess ?  i have several redirection same way, please helpThanks

Staff
29,997 Points
2016-10-27 10:21 am
Since you are using WordPress which also relies on .htaccess rules I recommend using a "301 redirect" plugin. This will reduce the chances of a rule interfering the the functionality of your site.

If you are determined to hand code this, it is covered in our guide on setting up a permanent 301 redirect via .htaccess.

Thank you,
John-Paul
2016-11-10 10:17 am
Thank you this post my website is working now.. i use this code
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]
this one will replace all your links to https
n/a Points
2016-11-18 8:19 am

Hi, some really useful examples here. Could you please help me out?I have a website and the customer wants everything to redirect to example.com/en/ by default.

Is there a single rule that will forward, http:// and http://www to https://www.example.com/en/ ?

I am asking for a single rule as my understanding is the fewer redirects the better for Google? Thank you!Adam

Staff
2,858 Points
2016-11-18 10:49 am

Adam, you should be able to use the following:


RewriteEngine on
RewriteCond %{HTTP_HOST} ^fromcrimsontowool\.com [OR]
RewriteCond %{REQUEST_URI} !^/en
RewriteRule ^(.*)$ https://www.fromcrimsontowool.com/en/$1 [L,R=301,NC]
n/a Points
2016-11-25 9:04 am

Thanks so much for your reply. However I just get an error when I use your code.

 

This is what I have that works, I just want to combine it into a single redirect:

# 301 to www

RewriteEngine On

RewriteCond %{HTTP_HOST} ^domain.com

RewriteRule (.*) http://www.domain.com/$1 [R=301,L]

 

# 301 to https

RewriteEngine On

RewriteCond %{HTTPS} !=on

RewriteRule ^(.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

Thanks.

n/a Points
2016-11-18 11:46 pm

I am forcing https as above without issue. However, some subdirectories have .htaccess files that use authorization via AuthType Basic. The authorization is happening pre-rewrite (in the clear, http). Is there a way to rewrite to https before authentication therefore securing the transfer of the user/pw within the https context?

Staff
43,761 Points
2016-11-21 4:59 pm
htaccess files are processed top-down. Do you get a better response by rearranging the order of the codes?
n/a Points
2016-11-22 6:13 am
Hello!
We recently purchased SSL certificate for our website. We currently have 2 redirects
 
For eg:
Original URL - http://www.example.com
Now after purchasing SSL:
https://www.example.com
 
How do I redirect users accessing HTTP version of the website to HTTPS WWW version of the website?
 
Currently I have 2 redirects - HTTP > HTTPS and then HTTPS > WWW as our website is using www preferred version.
 
My question is can I directly setup HTTP to HTTPS WWW redirect?
 
Kindly help

Thanks!

Staff
9,669 Points
2016-11-22 9:50 am
You will want to make sure that you redirect to the domain that is on the certificate, whether it is www or non-www.
n/a Points
2016-11-29 3:03 pm

I am trying to use an MVC approach in my site programming, that has one entry file index.php. How would I redirect to https with this approach? This is what I have in my .htaccess file right now:

RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php
Staff
9,669 Points
2016-11-29 6:12 pm
If you place the https redirect code above the code sample you provided you should not have any trouble.
n/a Points
2016-11-30 2:54 am

Thanks Brother.. I just loved it, cause it worked. Thank you so much...

 

n/a Points
2016-12-01 10:25 am

I love it: simple, elegant, and it worked perfectly for my site.

Thanks!

n/a Points
2016-12-15 2:38 am

# BEGIN WordPress

<IfModule mod_rewrite.c>

RewriteEngine On

RewriteCond %{SERVER_PORT} 80 

RewriteCond %{REQUEST_URI} folder 

RewriteRule ^(.*)$ https://www.****.co.uk/folder/$1 [R,L]

RewriteBase /

RewriteRule ^index\.php$ - [L]

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule . /index.php [L]

</IfModule>

 

# END WordPress

Thank you

I am using the above code and its working well but when i open my wp admin panel then its redirect to the home page and i couln't reach my dashboard so plz help me.

Staff
29,997 Points
2016-12-15 10:33 am
Since WordPress relies on .htaccess rules, we do not recommend adding code directly to the file.

Instead, you should enable SSL in your WordPress Site URL. This reduces the chances of a rule interfering with the functionality of WordPress.

Thank you,
John-Paul
n/a Points
2017-01-04 8:52 am

My website https://www.mywebsite.com, it is static website. and I want to clear my all canonical issues. for example if some one types https://www.mywebsite.com/index.php, https://mywebsite.com/index.php, https://mywebsite.com, http://www.mywebsite.com/index.php, http://mywebsite.com/index.php, http://mywebsite.com, my only one URL should come up or it should show, that is https://www.mywebsite.com. How I need to do?

Staff
13,701 Points
2017-01-04 9:51 am
You need to force either WWW or non-WWW and force either HTTPS or HTTP. This can be accomplished via the htaccess file.
n/a Points
2017-01-10 6:52 pm

Thank you sOooooOOOoo much, this worked perfectly :)

n/a Points
2017-01-18 12:31 am

I inserted the following code into my .htaccess file on the root directory.  I placed it at the top lines, above the lines of code that were already there.  Despite doing this, when I type in my website name as gunneria.com or www.gunneria.com, it goes to www.gunneria.com and not to https://www.gunneria.com.

 

Any idea what I am doing wrong?  Thanks for your help!

 

RewriteEngine On 
RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https://www.gunneria.com/$1 [R,L]
Staff
39,923 Points
2017-01-18 11:03 pm
Hello Tallyho,

We would need to see what else is in the file in order to assess the issue. Additionally, make sure that you don't have another .htaccess file that might be overwriting this one. Please first start that check and let us know if you require any further assistance.

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

Kindest regards,
Arnel C.

n/a Points
2017-01-24 10:48 am

Does the code above transfer Page Rank to the HTTPS site too?  I know I'm supposed to do a 301 redirect, but when I tried to do a 301 on top of this, the page would stop loading due to too many re-directs.

Staff
9,669 Points
2017-01-24 2:55 pm
If you are using a CMS like WordPress or Joomla, there are already existing .htaccess rules that can be causing the conflict. If that is the case, you may want to consider using a plugin to switch to https. In most cases, a sophisticated search engine should be able to tell it is looking at the same site with https instead of http. However, you can adjust your preferred protocol in something like Google's Webmaster Tools and then wait for Google to re-crawl the site.
n/a Points
2017-01-25 2:52 pm

Thanks for your response... I do use Wordpress... I noticed though, that Google started showing me search results with my new HTTPS URL where my old one used to be, so I hope that I'm good.  I did register the HTTPS account in GWT, as you also advised.  Thanks again!

n/a Points
2017-02-17 12:26 am

I am using OpenCart. I want call URL www.mydomain.com/api/common.php.

I added this new line in the .haccess file, but it's not working:

RewriteCond %{REQUEST_URI} !^/(qb|qb/.*)$

Please help me.

Thanks

Staff
2,858 Points
2017-02-17 10:25 am
Dao, as this has to do with making custom changes to the coding of your site or sites, it is outside of the scope of support that we are able to provide. You will want to work with an experienced web developer, if you don't have one already, to assist you in resolving this. Alternatively, you may wish to have a look at https://code.tutsplus.com/tutorials/the-ultimate-guide-to-htaccess-files--net-4757
n/a Points
2017-02-18 1:35 am

You really made my day, i was pulling my hair out as the ssl was installed properly but site was going to http:// instead of https:// and was showing connection not secure...

After the .htaccess change, everything worked as a charm.

By the way I am usinghost, domain and SSL all provided by godaddy...

 

n/a Points
2017-02-21 4:04 pm

My current .htaccess file currently has the following syntax:

# 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

 

I would like to force the domain.com to go to the www.domain.com everytime. I want to add something like the following to the .htaccess above:

Options +FollowSymLinks

RewriteEngine On

RewriteCond %{HTTP_HOST} ^domain.com[nc]

RewriteRule ^(.*)$ http://www.domain.com/$1 [r=301,nc]

 

The problem is that when I add this additional syntax to my .htaccess and then test the WordPress website, I get an error, "too many rewrite conditions."

 

Any ideas on how I should include the additional syntax into the existing .htaccess file?

Staff
2,858 Points
2017-02-21 4:27 pm
Alan, the easiest and most effective way to do this as you're using WordPress, is to update your site URL and WordPress address to use the www for your domain.
n/a Points
2017-02-22 11:28 am

THanks! it worked pretty well!

 

thanks!

n/a Points
2017-03-07 5:27 am

Great, easy-to-follow examples, thanks a lot. Have to say I'm pretty impressed by the inmotionhosting support pages - they're very well written.

 

n/a Points
2017-03-10 2:17 am

Hi,

I have:

 

RewriteEngine On 

RewriteCond %{HTTPS} off

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

 

in my .htaccess, and all of my pages forward to HTTPS properly except when the URL includes the page file name.

For instance, http://baytowntalkforum.com redirects to HTTPS, but http://baytowntalkforum.com/index.php does not. Same with http://baytowntalkforum.com/games.php, http://baytowntalkforum.com/members.php, etc.

Anytime the page's filename is included, it won't forward. I've searched all over the web and can't find a fix for this. Can you help, please?

Thanks,

D

Staff
2,858 Points
2017-03-10 4:01 pm
D, I used your exact code on a brand new site with only three files. A test index.php, a phpinfo.php file, and a .htaccess file that only had your code in it. My site redirected even if I put a filename at the end. This would indicate either a browser caching issue, or an issue with your web hosting setup. I recommend clearing your browser cache, and trying again.
n/a Points
2017-03-12 4:51 am

Hi Dorian,I use the code below and work great:

 RewriteEngine on  #RewriteBase / RewriteCond %{HTTP_HOST} ^www.example.com [NC]  RewriteRule (.*) http://example.com/$1 [R=301,L]RewriteCond %{HTTPS} offRewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]If not work remove the part #RewriteBase / .

Check my website for example:gamesunblocked.us.

Try all version in your browser.

n/a Points
2017-03-14 7:13 pm

I need help, i forced ssl on all pages of my website but the layout is scattered... any advice? 

Staff
13,701 Points
2017-03-15 8:27 am
Sounds like some of your resources are loading over HTTP. Make sure your CSS, images, and JS all load over HTTPS. Depending on how your website is built this can be accomplished many ways. If it's a WordPress website, there's a plugin to force HTTPS which works well.
n/a Points
2017-03-15 6:32 pm

Just wanted to say thank you for this post... know it's been up for a while, but for some reason I can't get the htaccess rules to stick in my head. Use this post to jog my memory more than I am comfortable admitting :-/

n/a Points
2017-03-17 3:28 am

Dear sir I have a webhosting account of hostgator and I am using more than 5 domains in one account.

1 is main domain and others are addon domains.

whenever I have used any code which is like this 

it gives the several redirections error

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

please suggess me if htaccess of main domain is infecting on addon domains.

Staff
2,858 Points
2017-03-17 3:11 pm
Abdul, I don't see anything wrong with your current .htaccess code, but ultimately I'm not a website developer. I would, however, point out that .htaccess files are recursive. This means that any .htaccess file that you have in a parent folder will affect all the child folders.
n/a Points
2017-03-19 5:19 am

Thank you for this little tutorial. I have a problem now:

http:// traffic redirects to https://www.

https:// traffic redirects to https://www.

But http://www. traffic doesn't redirect to https://www.

Is there any way to fix this as well?

I have to mention that I tried a lot of .htaccess codes, but every single one gave me a redirect loop and only the codes on this page have worked so far. I have a simple Let's Encrypt certificate issued on its related page in cPanel, but I have not been able to install it on the SSL/TLS page. (Private Key problem)

Staff
43,761 Points
2017-03-20 1:53 pm
The second example given should work for you. This should redirect anything with example.com (your domain) to https://www.example.com

You may want to rename the current .htaccess file and test it with a new blank one. If it works, then remove that file and rename the original one back to .htaccess and insert it at the top of the file. Be sure to remove any other failed code prior to inserting the working one.
n/a Points
2017-03-19 6:37 pm

Hi,

thanks for putting the time i to monitor this interesting thread.

I am thinking of using this code to redirect login.php to https.

RewriteCond %{SERVER_PORT} 80RewriteCond %{REQUEST_URI} ^/(login\.php) # Will force SSL on login.phpRewriteRule ^(.*)$ https://www.mywebsite.co.uk/login.php$1 [R,L]

Problem is I have a login.php in www.mywebsite/admin/login.php, will this not redirect my admin login to the customer login page?

Best fix? I may just have to rename my admin login page if not.

Staff
43,761 Points
2017-03-20 1:54 pm
You may want to put an .htaccess file in the /admin folder with just the redirect code in it. That should govern that specific file.
n/a Points
2017-04-04 1:35 pm

Hi

I am using the following for SSL

#Rewrite everything to https

RewriteEngine On

RewriteCond %{HTTPS} !=on

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

I now want to change the following url

https://www.website.com/index.php?p=1

to

https://www.website.com/1/

I have tried various options but can't get any of them to work.

Any suggestions?

Many thanks

 

Staff
9,669 Points
2017-04-04 1:47 pm
Those do not appear to be the correct syntax. I advise copying and pasting one of the above snippets from this article.
n/a Points
2017-07-14 8:30 pm

The article is incorrect for the recent changes to the auto ssl -> lets encrypt which writes its own code into the the htaccess file

 

Since the httpd.conf file can not be relied on to function with distiller - as this does not function either - you need a top level redirect

 

RewriteCond%{HTTPS}!=on
RewriteRule^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
n/a Points
2017-04-17 1:11 am

when i insert the code in htaccess the code is running but your connection is not fully secure error going on what i do for fully secure can you guide me step by step

Staff
43,761 Points
2017-04-17 2:52 pm
This is most often due to some links on the page connecting to http and not https. You will need to correct those in order for the page to be fully secure.
2017-04-25 3:15 pm
This one seems to be correct with the 301. IMH you might wish to update your example.

RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]
n/a Points
2017-05-17 3:09 am

Hi,

I am using heroku with Cakephp 3

My .htaccess code looks like this

I want to redirect http://redpolka.com/ to https://www.redpolka.com/

I can't reach out to heroku they are not reachable.Tried every stack overflow but none of them worked.

##Force SSL #Normal way (in case you need to deploy to NON-heroku)RewriteCond %{HTTPS} !=on#Heroku wayRewriteCond %{HTTP:X-Forwarded-Proto} !https #If neither above conditions are met, redirect to httpsRewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Staff
39,923 Points
2017-05-17 11:25 am
Hello,

Sorry for the problem with using Heroku. If the .htacess changes are not working then you may need further configuration for the change. You will need to consult with their technical support as we are not familiar with their particular application.

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

Regards,
Arnel C.
n/a Points
2017-08-03 10:16 pm

I installed SSL on my server and added the code on the guide. But still get this errorAn error occurred during a connection to www.motobuy.com.ph. SSL received a record that exceeded the maximum permissible length. Error code: SSL_ERROR_RX_RECORD_TOO_LONG

Thanks

Staff
9,669 Points
2017-08-04 11:22 am
It looks like the SSL was either installed or configured improperly. I advise contacting Live Support if you are hosted with us.
n/a Points
2017-09-15 6:17 pm

Watch out for this issue with cPanel and AutoSSL. cPanel will edit your .htaccess files unless you prevent it.

https://features.cpanel.net/topic/ability-to-prevent-autossl-editing-htaccess-fles

https://features.cpanel.net/topic/autossl-act-differently-based-on-apache-version

Staff
1,423 Points
2017-09-15 6:30 pm
Thanks for the heads up on that! We appreciate your feedback regarding this guide.
n/a Points
2017-09-23 2:01 pm

Hi,

I have SSL for a domain but not subdomain. I have a mobile site and if i use the code your code i get ssl error on the mobile site. masically i want all traffic to www.mydomain.com to redirect to https://www.mydomain.com but m.mydomain.com to remain http.

I´m using the code bellow, is this the correct code or you have a better solution. 

 

RewriteCond %{HTTPS} off

RewriteCond %{HTTP_HOST} www.mydomain.com

RewriteCond %{REQUEST_URI} !/robots.txt

RewriteRule (.*) https://www.mydomain.com/$1 [R=301,L]

Staff
337 Points
2017-09-25 2:13 pm
Hello,

I don't see anything wrong with that but I do not see any redirects for the mobile site in that code. I would think the simplest solution would just be to force SSL on the main domain and then you redirect to the mobile site ensure the redirect is specifying http instead of https.

Best Regards,
Kyle M
n/a Points
2017-09-27 8:24 pm

just fixed ssl problem in my site

https://www.newspaperasia24.com/

Staff
1,423 Points
2017-09-27 9:10 pm
Great! We are glad to see that.
n/a Points
2017-10-02 2:15 am

Hello there,

I wasn't sure which code to use for my problem. Here is my issue.

My website is indexed two weeks back. It has HTTPS or SSL certificate installed.

Actually it looks like this: https://example.com/

But it is indexed in Google in two versions, like this: example.com/ and https://example.com/

Now, I don't want example.com/ in Google Index. I've been waiting to see if it naturally goes off from the Google Index. But it is not.

How can I redirect this (example.com/) to https://example.com/? In my sitemap also, I have this version - https://example.com/. Please help me solve this issue.

Staff
13,701 Points
2017-10-02 8:48 am
The instructions to force HTTPS are at the top of this article. If you read through it and have specific questions let us know.
n/a Points
2017-10-05 11:37 am

Any idea how to configure the htaccess file for cloudflare server? 

https://allthewayupmedia.com/

Staff
39,923 Points
2017-10-05 11:53 am
You can find more information about CloudFlare in their Support Forums. If you're trying to whitelist their IPs, then check out this post.

n/a Points
2017-10-14 8:57 am

Dear Sir

This article help me to redirect my new domain aglatax.com to https, I face https redirect problem from many days, but after following your guide i am successfully redirect my website.

Thanks again

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.

144 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!