Forward HTTPS non-WWW to HTTPS WWW

#1
Hi,

I am having issues on my domain where all other url: example.org, www.example.org, both HTTP points to my https://www.example.org, but when I access the https://example.org, it does not redirect to the https://www.example.org.

I am using the Wordpress OpenLiteSpeed in DigitalOcean and have used most of the solutions in wordpress and OpenLite Speed Forum. I also tried using the plugin-Redirect and still not successful.

I managed to add this code in my .htaccess in /var/www/html as per suggested.

1587387875356.png
Any help is much appreciated.

Thanks
 
#3
Hi,

Eric. Thanks for the quick response. Yes I have. Every time I update my htaccess, i do a restart.

Also, if it helps, I have also tried these separately:

Code:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]
Code:
RewriteCond %{HTTP_HOST} ^yourdomain.com [NC]
RewriteRule ^(.*)$ http://www.yourdomain.com/$1 [L,R=301]
Code:
RewriteCond %{HTTPS} !^on$
RewriteRule (.*) https://www.website.co.uk/$1 [R,L]
Given that I swap my domain to those placeholders.
 
#4
This is what you need to do for your HTTPS redirect. If you're using Wordpress, make sure that you change the default URL to your site and dashboard to include HTTPS://WWW. YOURWEBSITE. If you don't do this you won't be able to access your Wordpress dashboard. Had the same problem and probably Litespeed need to include it by default when it comes to redirecting from non-HTTP WWW to HTTPS WWW

Then rewrite your .HTACCESS file with the following condition

Code:
RewriteCond %{HTTP:X-Forwarded-Proto} !^https$ [NC]
RewriteCond %{HTTPS} !^on$ [NC]
RewriteRule .* https://www.yourwebsite.com%{REQUEST_URI} [R=301,L,NE]
 
#5
This is what you need to do for your HTTPS redirect. If you're using Wordpress, make sure that you change the default URL to your site and dashboard to include HTTPS://WWW. YOURWEBSITE. If you don't do this you won't be able to access your Wordpress dashboard. Had the same problem and probably Litespeed need to include it by default when it comes to redirecting from non-HTTP WWW to HTTPS WWW

Then rewrite your .HTACCESS file with the following condition

Code:
RewriteCond %{HTTP:X-Forwarded-Proto} !^https$ [NC]
RewriteCond %{HTTPS} !^on$ [NC]
RewriteRule .* https://www.yourwebsite.com%{REQUEST_URI} [R=301,L,NE]
Hello . I use http to https , with no www . Also i use for the first time openlitespeed , can i use the same redirect as i have also problem that my sites opens with http (i use ssl) which is not secure .
Another 1 question if y have idea how i can add mod rewrite properly as i have some links that goes to 404 error too many redirects so i cant use seo url,great problem with redirects . Im totally confused + lscache is not working , but this s another theme . Ty so much . I hope you are around
opencart , php 7.3 , openlitespeed .

i will upload my htaccess file just if y have min to check it . If its possible of course . I m still confused . Ty again
 

Attachments

#6
Hi,
I am sorry if I ask stupid questions, but I am still trying to understand how this works.

Do you add the rules both to the vhost and httaccess file? How are the rules parsed if there is conflicting rules on the vhost or the httaccess file?
Is there a best practice where to add the rules?

I am trying to redirect all http/https request for domain.com to https://www.domain.com. This works fine when using only domain.com, but when using https://domain.com (with the protocol added to the URL) the rule don't work.

My Wordpress default URL is https://www.domain.com

The rewrite rule on the vhost is:
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www.
RewriteRule ^(.*)$ https://www.domain.com/$1 [R=301,L]
 
Top