Redirecting from Http to Https with AWS's ELB in Chrome and FireFox

匆匆过客 提交于 2019-12-13 17:19:03

问题


I have setup redirecting from http to https at AWS with ELB. The procedure is as follow.

In the file .htaccess, put the following X-Forwarded-Proto code

<VirtualHost *:80>
    RewriteEngine On
    RewriteCond %{HTTP:X-Forwarded-Proto} !https
    RewriteCond %{HTTP_USER_AGENT} !^ELB-HealthChecker
    RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]
</VirtualHost>

Then the .htaccess file is put inside the folder my website's index.php stays.

I tested at Chrome, FireFox and Safari. Both Chrome and Safari work, but FireFox doesn't.

At both Chrome and Safari, when I key in www.domainname.com at browser, I see the change in the browser as https://www.domainname.com. Same to Safari as well.

But in Chrome, when I key in www.domainname.com, the page is loaded with http://www.domainname.com. Even I keyed in as http://www.domainname.com, it is by itself changed to https://www.domainname.com.

What could be wrong? Is that redirecting still doesn't work at FireFox?


回答1:


I am solving the issue for a long time and now can make it works successfully. I like to share what I have done as follows.

(1)Create .htaccess file inside the folder same as root file index.php exists
(2).htaccess file has
RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} =http
RewriteRule . https://%{HTTP:Host}%{REQUEST_URI} [L,R=permanent]
(3)Then enable mod_rewrite, try the command line command: 
   sudo a2enmod rewrite
(4)To make sure mod_rewrite is enabled, update /etc/apache2/apache2.conf file as
<Directory /var/www/html>
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
</Directory>
initially was 
<Directory /var/www/>
        Options Indexes FollowSymLinks
        AllowOverride None
        Require all granted
</Directory>

Then you can setup http to https successfully
You need to restart server as sudo service apache2 restart after update of /etc/apache2/apache2.conf 


来源:https://stackoverflow.com/questions/43713304/redirecting-from-http-to-https-with-awss-elb-in-chrome-and-firefox

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!