Openlitespeed force www

Hello all.

I tryed searching for an answer to my question, but seemess like the answers is a bit old/legacy.

My question and issue: I want to display the wwwDOTmydomainDOTcom instead of

Im a beginner host, and been trying this for a few days now, and never would i imagine it being this hard.

I run openlitespeed and cyberpanel. I run a WordPress site with litespeed cache and cdn.

When I try to set the non-www → www template rule in my rewrite, the adresse bar changes indeed to www.mydomainDOTcom , but a warning is thrown saying i have too many redirections going on.

I tryed moving the line of code below is cache and above WordPress, and around, still same redirect error.

What I noticed, that seemes weird, is that if i remove the rule, my website works fine like this domainDOTcom . If i then remove the www cname that points to the root, it is being redirected to www.mydomainDOTcom , but the page is not found. This is without the rewrite rule.

Someone please help. Im about to go crazy :frowning:

Found a new rewrite rule:

# BEGIN Redirects
RewriteEngine On
# 301 redirect to www
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# 301 redirect to https
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# END Redirects

Still same. Browser redirects too many times.

Welcome and Happy New Year @seegon

Try these rules

RewriteEngine on
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^$ [R=301,L]

You can add ^$ [NC] at the end of the query strings match policy to match case insensitive query string. This can also be done for hostname or path also. e.g.

RewriteCond %{QUERY_STRING} ^$ [NC]
RewriteRule ^$ [R=301,L,NC]

This also causes a redirect loop.

In my inspect tool, under network, i find it switching between 301 and 301 - the later is named WordPress for some reason.

Not sure whats going on.

This should work I have it for some of my websites. However there is one that works with wordpress.

Go to Websites → List Websites → mycoolwebsite → Rewrite Rules

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
# everything else goes down here

I had to rewrite it to make it force www and not non-www, but then it throws a redirect loop.

I have no idea where this extra 301 redirect is coming from.

Thanks for trying to help our though.

Conflicting redirects are mostly caused by htaccess or a CDN misconfiguration.Remedy is to clear cache, cookies or use another browser entirely. You should try with only the rules I gave you delete the rest adn test.

You should also update the website url with mysql or just use phpmyadmin and edit the values in wp-options table

## check the home URL and site URL lines in the wp-options table
$ mysql -e 'select * from wp_options where option_name rlike "home|siteurl"' database_name

## update it with our
$ mysql -e 'update wp_options set option_value="" where option_name rlike "home|siteurl"' database_name

If all fails maybe try this plugin GitHub - wp-media/wp-rocket-helpers: 🚀 Helper plugins for specific use cases with WP Rocket. ☝️ TEST BEFORE USE! ☝️