HTTPS redirect problem

Hello,

I want to redirect all request to https included www subdomain. I added rewrite rule from cyberpanel but doesnt work…

My .htaccess like this

Options -MultiViews -Indexes
RewriteEngine On

# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]

# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

and I added this rule on cyberpanel

RewriteCond %{HTTPS} !on
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [R,L]

How did you add rules, Did you follow this guide?

My dashboard is not like in the docs but I put rewrite rules to same place

RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Use these simple rules.

it didnt work

Did you remove all other rules and try this one, and make sure your application does not force http version.

These rules should work, as we are using same on our end.

hi again,

I’m using just the rules you gave me. maybe my .htacces cause this problem ? Can you take a look ?

vow I think I found what is problem and why my rules arent working.

I use PHP Laravel Framework and Laravel use public folder for stream not the public_html. by default. I changed public_html to public folder. But cyberpanel is trying still read and write rewrite rules from public_html folder. I become aware of this when I deleted public_html folder and tried change rewrite rules.

How can I change default rewrite rule folder ?

That does not matter for HTTPS redirect at least. Did you change the docRoot path in vHost Conf?

If you manually change the docRoot path in vHost Conf, then make sure that directory contains your .htaccess, you can use File manager to manually create .htaccess, because by default CyberPanel will use /home/domain.com/public_htmlto place your rewrite rules.

And when you save rewrite rules from File manager, don’t forget to restart OpenLiteSpeed.

I changed docRoot root as public folder and contains .htaccess file

My .htaccess like this

Options -MultiViews -Indexes
RewriteEngine On

# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]

RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

I tried reboot ols but didnt work. I reboot my server it is working now… Thanks for your helps…

Better use CyberPanel default paths, and copy your application accordingly.

Type your comment> @CyberPanel said:

That does not matter for HTTPS redirect at least. Did you change the docRoot path in vHost Conf?

If you manually change the docRoot path in vHost Conf, then make sure that directory contains your .htaccess, you can use File manager to manually create .htaccess, because by default CyberPanel will use /home/domain.com/public_htmlto place your rewrite rules.

And when you save rewrite rules from File manager, don’t forget to restart OpenLiteSpeed.

it’s work.
systemctl restart lsws

So, what is the correct way to deploy a laravel app? using the current git feature?

I deploy my app, and attach a git repo to the public_html folder(only you can attach the repo to the public_html folder), then I change the docRoot path as you say

Did you change the docRoot path in vHost Conf?

to public_html/public

with this, my app does not redirect to https, the certificate works if you type the https, bu not if you type only the domain.

Thanks!