How to fix HTTPS redirect not working in OpenLiteSpeed

When running WordPress on an OpenLiteSpeed ​​web server , the default redirection from HTTP to HTTPS often doesn’t work properly.

Another issue that can occur when setting up a reverse proxy is a 404 error when accessing HTTP. This can cause the reverse proxy to not be set up properly.

Therefore, when installing OpenLiteSpeed, it is important to set up Virtual Host Mappings to avoid 404 errors when accessing HTTP. This setting can be easily added if you have Webadmin installed and accessible.

Accessing .htaccess

Redirect

If you are using the OpenLiteSpeed ​​web server, you probably have CyberPanel installed as well. Simply go to http://ipaddress:8090 , go to Websites > List Websites, and then click Manage to the right of your website.

Then you can find Rewrite Rules in Configurations. Here you can add your Redirect code.

If you haven’t installed CyberPanel, there is a function in the SEO plugin settings to edit the .htaccess file, so you can add it there. If it’s not WordPress, you can add it using the FileZilla program.

Add redirect code

※ If you add incorrect code to .htaccess, the site may not function properly.It is important to make a backup before starting any work.

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

RewriteEngine On
RewriteCond %{HTTP_HOST} ^XX\.XX\XX.\.XX$ [OR]
RewriteCond %{HTTP_HOST} ^XX.XX.XX.XX$
RewriteRule ^(.*)$  [R=301,L]

The first code is to set a 301 Redirect to HTTPS when accessing via HTTP.

The second code is a rule that redirects to the domain page when accessed by IP address. It is recommended to redirect IP access as well, so you can add this rule as well. Just change the XX.XX.XXX.XX part to your server IP address.

After adding the above code, if you access HTTP from your browser, the HTTPS Redirect should work properly. However, if the Redirect does not work, you can solve the problem by applying the settings below.

When redirect doesn’t work

Redirect

If the redirect does not work, you can add Virtual Host Mappings in the Port 80 settings after accessing the WebAdmin tool.

After accessing Webadmin with http://server IP address or domain:7080, select ‘Listeners’ from the left menu and find port 80. Then, click on the port to enter the settings.

Redirect

If you have entered the 80 port settings, click the + button in Virtual Host Mappings located at the bottom of the General tab.

Redirect

Once you’ve entered Virtual Host Mappings, select your domain in Virtual Host, add the domain address, IP address, and localhost in Domains, and then click the Save button shaped like a diskette on the right.

Finally, click on the IP address at the top left of the Webadmin and restart the web server.

Now, when you access http://your domain in your browser, you will see that it is automatically redirected to https. The important thing here isYou should clear your browser’s cache or use a different browser to see accurate results.You can do it.

How to check if it works on the server

Redirect

A way to check on the server is to enter http://domain address or http://IP address in the Curl -I command. If HTTP/1.1 301 Moved Permanently is returned, it is operating normally.

▶ How to install dual WordPress on CyberPanel

▶ How to Resolve CORS Errors on the OpenLiteSpeed Web Server

▶ How to apply the HTTP/3 protocol to the OpenLiteSpeed web server

Leave a Comment

Your email address will not be published. Required fields are marked *