CyberHosting

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]

Comments

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

    http://prntscr.com/mp7j8v
  • edited February 2019
    <pre>RewriteCond %{HTTPS} !=on
    RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]</pre>

    Use these simple rules.
  • 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 ?
  • edited February 2019
    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.

    http://prntscr.com/mpfp3p

    How can I change default rewrite rule folder ?
  • edited February 2019
    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

    http://prntscr.com/mpg310

    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]


  • edited February 2019
    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.
  • edited December 2019
    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
Sign In or Register to comment.
CyberPanel Discord

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!