简体   繁体   中英

HTTPS under Amazon EBS + Apache on ubuntu on EC2 not redirecting HTTP

I have a EBS machine running ubuntu 16.04 and Apache2 which is receiving HTTPS requests from a EBS. I`m having problems on trying to redirect HTTP requests to HTTPS.

So far I tried to redirect using .htacces and mod_rewrite .

.htaccess:

RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} =http
RewriteRule . https://%{HTTP:Host}%{REQUEST_URI} [L,R=permanent]

How can I redirect the HTTP requests to HTTPS?

Try like this:

RewriteEngine On
    RewriteCond %{HTTPS} off 
    RewriteRule (.*) https://%{SERVER_NAME}/$1 [R,L]

I found a solution.

Instead of using a .htaccess file I wrote the rules on apache .conf file.

Here is it:

RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} =http
RewriteRule . https://%{HTTP:Host}%{REQUEST_URI} [L,R=permanent]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM