使用 Chrome 和 FireFox 中的 AWS ELB 从 Http 重定向到 Https
Redirecting from Http to Https with AWS's ELB in Chrome and FireFox
我已经设置了使用 ELB 在 AWS 上从 http 重定向到 https。流程如下
在.htaccess文件中,放入以下X-Forwarded-Proto代码
<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>
然后将.htaccess 文件放入我网站index.php 所在的文件夹中。
我在 Chrome、FireFox 和 Safari 上进行了测试。
Chrome 和 Safari 都可以,但 FireFox 不行。
在 Chrome 和 Safari 中,当我在浏览器中键入 www.domainname.com 时,我在浏览器中看到的更改为 https://www.domainname.com。 Safari 也一样。
但是在 Chrome 中,当我输入 www.domainname.com 时,页面加载了 http://www.domainname.com。即使我输入了http://www.domainname.com,它自己也变成了https://www.domainname.com.
有什么问题吗?重定向在 FireFox 上仍然不起作用吗?
我解决了很久的问题,现在可以成功运行了。
我喜欢分享我所做的如下。
(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
我已经设置了使用 ELB 在 AWS 上从 http 重定向到 https。流程如下
在.htaccess文件中,放入以下X-Forwarded-Proto代码
<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>
然后将.htaccess 文件放入我网站index.php 所在的文件夹中。
我在 Chrome、FireFox 和 Safari 上进行了测试。 Chrome 和 Safari 都可以,但 FireFox 不行。
在 Chrome 和 Safari 中,当我在浏览器中键入 www.domainname.com 时,我在浏览器中看到的更改为 https://www.domainname.com。 Safari 也一样。
但是在 Chrome 中,当我输入 www.domainname.com 时,页面加载了 http://www.domainname.com。即使我输入了http://www.domainname.com,它自己也变成了https://www.domainname.com.
有什么问题吗?重定向在 FireFox 上仍然不起作用吗?
我解决了很久的问题,现在可以成功运行了。 我喜欢分享我所做的如下。
(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