WWW and non-WWW with OpenLiteSpeed

I’ve recently reorganized my use of virtual servers for my company’s web sites, which led to me having one site that does not use a control panel, and just has one website on it.

Oddly, even though I’d read up on how to redirect www to non-www and have the SSL certificate handle the result, it wasn’t working. I got various issues with the www form, which I thought I was directing to non-www.

As often is the case, this turns out to have been an annoying oversight on my part, but since I saw a number of cases where a similar oversight was included in sample code, I thought I’d post this to help anyone else find the answer.

RewriteCond %{SERVER_PORT} ^80$
RewriteCond %{SERVER_PORT} ^443$
RewriteCond %{HTTP_HOST} ^(www\.)?yourdomain\.com [NC]
RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]

It was the second line that was missing. Once I had entered that line, everything started working with no problems. You set this rewrite from the OpenLiteSpeed Webadmin Console, Virtual Hosts, Rewrite. See the image below.

Similar Posts

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.