How to redirect to a folder and HTTPS simultaneously?

Asked

Viewed 283 times

3

I have a website http://meusite.pt which is a CNAME of http://minhamaquina.amazon.com, where the hosted site is. Only that I needed it to be redirected to the folder meusite from my Amazon machine, namely, http://minhamaquina.amazon.com/meusite, but only to remain visible http://meusite.pt.

I got that with this answer: https://stackoverflow.com/a/36972084

RewriteEngine on 

#RewriteCond %{HTTPS} !=on
#RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI}

RewriteCond %{HTTP_HOST} ^(www.)?meusite.pt$ 
RewriteCond %{REQUEST_URI} !^/meusite/ 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 

RewriteRule ^(.*)$ /meusite/$1 

RewriteCond %{HTTP_HOST} ^(www.)?meusite.pt$ 
RewriteRule ^(/)?$ meusite/ [L]

My problem now is that I also need to redirect http to https, that is if I type http://meusite.pt it will redirect to https://meusite.pt that will have to fetch the contents to http://minhamaquina.amazon.com/meusite.

The certificate is in meusite.pt.

It is possible to do this with the .htaccess? Like?

[EDIT]

I added the (commented) lines of the question that was indicated as duplicate, but is on loop:

This webpage has a loop redirect

1 answer

0


I figured out a way to do on Soen that solved my problem, it’s not really an answer to what I asked, but it’s the solution of the problem, which is basically to use the lines that were suggested to me in the comments in an Amazon configuration file as we can see in this answer.

In short, simply put a file .config on the board .ebextensions of the project the following:

files:
    "/etc/httpd/conf.d/ssl_rewrite.conf":
        mode: "000644"
        owner: root
        group: root
        content: |
            RewriteEngine On
            <If "-n '%{HTTP:X-Forwarded-Proto}' && %{HTTP:X-Forwarded-Proto} != 'https'">
            RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
            </If>

That when deploying the application adds this rule to the Apache of Elastic Beanstalk.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.