cancel
Showing results for 
Search instead for 
Did you mean: 
Go to solution
Jennn
Skilled

Code to Force https://www redirect

I just moved my site from a shared windows server to a shared Linux server. I want to redirect the four versions of my site (http, https, with and without the www) to the preferred url: https://www.sun.... 

 

I currently have: 

 

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

 

in my .htaccess file. It redirects my pages to the https version but does not redirect to the https://www preferred version.  I've been told I can add code to my .htaccess file to force the www versions of my site.  I was given this code:

 

RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301,NC]

 

If I add the following to my .htaccess file will the preferred redirection work so all versions of my site redirect to the https://www.sun... version?

 

RewriteCond %{HTTP_HOST} ^sun... [NC]

RewriteRule ^(.*)$ https://www.sun (my site)/$1 [L,R=301,NC]

 

Thanks for your help!

 

2 REPLIES
GoDaddy Pro Mentor
GoDaddy Pro Mentor
Solution

Re: Code to Force https://www redirect

Please take a look at the Godaddy Official Article for the help and follow the steps.

Please give it a +1 and also click "Mark As Accepted Solution" if you find it satisfactory. Thanking You With Regards | Harry Parmar
joelkers
Novice

Interaction between HTTP to HTTPS redirects and 301 redirects

Recently my firm revamped its website. In the process, we switched to HTTPS. Godaddy's automatic domain level redirects from the HTTP URLs to HTTPS have worked without problem. However, 301 redirects I set up for a series of pages from our old site - intended to move search engine/legacy link traffic to corresponding pages on the new site - are generally not working.

 

To be precise, while they do not work from HTTPS, which is the full path that appears in search engine results, they do work perfectly if the 's' in HTTPS is deleted from the URL in question.

 

For example, let's say www.acme.com/about-us.html should  redirect to www.acme.com/about. In Google's search results, there is a link to https://www.acme.com/about-us.html. If I click on the link, it goes to this URL, not https://www.acme.com/about, per my redirect. However, if I remove the 's' from the URL and click enter, the 301 redirect works as it's supposed to, and forwards me to https://www.acme.com/about.

 

Another anomaly is that the redirect does work normally for one page which had been scrubbed from links within the site, but which was still accessible by typing the URL directly.

 

I've tried to make some sense of the various patterns for redirects in .htaccess, but aside from complexity, I'm concerned about interactions between whatever changes I make to the 301 rules applied via the cPanel redirect module and the domain level HTTP to HTTPS rules.

 

Is there a low-risk solution to this issue that will preserve the domain level HTTP to HTTPS while also permitting the URL-specific 301 redirects to work as intended?

 

Any help is greatly appreciated.