我有一个在myapp.com上的反应应用程序,其中安装了SSL证书。当我在浏览器中输入myapp.com时,它会像预期的那样转到https://myapp.com。如果我从那里导航到/shop,它仍然是安全的。
但问题是当我在url中手动输入myapp.com/shop时。则该连接是不安全的。
这是我的.htaccess文件:
RewriteEngine On
RewriteBase /
RewriteRule ^index.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule . /index.html [L]
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
# php -- BEGIN cPanel-generated handler, do not edit
# Set the “ea-php73” package as the default “PHP” programming language.
<IfModule mime_module>
AddHandler application/x-httpd-ea-php73 .php .php7 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit发布于 2021-05-30 23:45:18
您缺少重写规则[R,L]的标志
完整代码:
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]另一种最佳实践是使用端口检查来更改HTTPS检查,但这是可选的,因为您的代码也应该可以正常工作。
RewriteCond %{SERVER_PORT} 80
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]https://stackoverflow.com/questions/67762971
复制相似问题