问题
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