redirection to https not work for specific condition

Discussion in 'Feature Requests' started by Poliman, Oct 15, 2018.

  1. Poliman

    Poliman Member

    Hello. I use ISP 3.1.13 under Ubuntu 16.04 LTS. I have there few websites. I tried set redirect to https for one of them (https without redirection works perfect). Below is part of 100-example.pl.vhost file included in VirtualHost for port 80 (there is L redirect to /public/biogame/, SEO redirect from www to non-www and turned on php-fastcgi):
    Code:
                   
                    RewriteEngine on
                    RewriteCond %{REQUEST_URI} ^/\.well-known/acme-challenge/
                    RewriteRule ^ - [END]
                    RewriteCond %{HTTP_HOST} ^www\.example\.pl$ [NC]
                                    RewriteRule ^(.*)$ http://example.pl$1 [R=301,NE,L]
                    RewriteCond %{HTTP_HOST}   ^example\.pl$ [NC]
                                    RewriteCond %{REQUEST_URI} !^/webdav/
                    RewriteCond %{REQUEST_URI} !^/php-fcgi/
                    RewriteCond %{REQUEST_URI} !^/public/biogame/
    
                    RewriteRule   ^/(.*)$ /public/biogame/$1  [L]
    
                    RewriteCond %{HTTP_HOST}   ^www\.example\.pl$ [NC]
                                    RewriteCond %{REQUEST_URI} !^/webdav/
                    RewriteCond %{REQUEST_URI} !^/php-fcgi/
                    RewriteCond %{REQUEST_URI} !^/public/biogame/
    
                    RewriteRule   ^/(.*)$ /public/biogame/$1  [L]
                    RewriteCond %{HTTPS} off
                    RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]
    
    In above code at the bottom is added part when in ISP user click checkbox "Redirect HTTP to HTTPS":
    Code:
     
                    RewriteCond %{HTTPS} off
                    RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]
    
    but it doesn't work. I found out that it works when above part is directly behind the line "RewriteEngine On" like below:

    Code:
                    RewriteEngine on
                    RewriteCond %{HTTPS} off
                    RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]
                    RewriteCond %{REQUEST_URI} ^/\.well-known/acme-challenge/
                    RewriteRule ^ - [END]
                    RewriteCond %{HTTP_HOST} ^www\.example\.pl$ [NC]
                                    RewriteRule ^(.*)$ http://example.pl$1 [R=301,NE,L]
                    RewriteCond %{HTTP_HOST}   ^example\.pl$ [NC]
                                    RewriteCond %{REQUEST_URI} !^/webdav/
                    RewriteCond %{REQUEST_URI} !^/php-fcgi/
                    RewriteCond %{REQUEST_URI} !^/public/biogame/
    
                    RewriteRule   ^/(.*)$ /public/biogame/$1  [L]
    
                    RewriteCond %{HTTP_HOST}   ^www\.example\.pl$ [NC]
                                    RewriteCond %{REQUEST_URI} !^/webdav/
                    RewriteCond %{REQUEST_URI} !^/php-fcgi/
                    RewriteCond %{REQUEST_URI} !^/public/biogame/
    
                    RewriteRule   ^/(.*)$ /public/biogame/$1  [L]
    
     
  2. Jesse Norell

    Jesse Norell Well-Known Member

    There is a semi-related issue to improve the redirects for seo/efficiency purposes when using both SEO and http->https redirects; this is a separate bug it seems when you additionally have a redirect to a path within the site. Likely they could both be addressed at the same time.

    I'll note that you should put the https redirect after the /.well-known/acme-challenge/ exclusion, or I expect letsencrypt might break (ie. be unable to verify certificates in the future).
     
  3. Poliman

    Poliman Member

    I am going to check it. ;)

    EDIT
    I checked it. Redirection to https does not work when I put:
    Code:
                    RewriteCond %{HTTPS} off
                    RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]
    
    right after:
    Code:
    RewriteCond %{REQUEST_URI} ^/\.well-known/acme-challenge/
    
    I also tried to paste it lower but this same result - redirection does not work.
     
    Last edited: Oct 16, 2018
  4. Jesse Norell

    Jesse Norell Well-Known Member

    The acme-challenge lines include:
    Code:
                   RewriteCond %{REQUEST_URI} ^/\.well-known/acme-challenge/
                   RewriteRule ^ - [END]
    Try putting it right after those.
     
    Poliman likes this.
  5. Poliman

    Poliman Member

    It looks like it works in this form. Could it be considered as bug and fixed in new ISP version?
     
  6. till

    till Super Moderator Staff Member ISPConfig Developer

    Poliman likes this.
  7. Poliman

    Poliman Member

    Thank you.
     

Share This Page