如何使用 .htaccess 或 PHP 使所有 HTTP 请求都通过 HTTPS
好的,这是我的问题,我有一个通过 https 传递的文件,我的服务器上的所有文件都有一个包含在文件中的通用 header.php 文件。在头文件中,我从我的 cdn 文件夹中调用了所有样式表等。 http://cdn.domain.com 因为它们在我的 https 文件中被称为 http (通过 header.php)它不完全以 https 传输。
有没有办法让 htaccess 通过 https 进行 https 页面上的所有交易,即使它试图获取 http 版本?或者我最好的选择是用 PHP 进行编码?
谢谢
Ok here's my issue I have a file that is delivered through https, all the files on my server have a common header.php file that is included within files. In the header file i have all my stylesheets etc called from my cdn folder. http://cdn.domain.com since they are called http in my https file (via header.php) it doesnt transmit fully in https.
Is there a way to have htaccess make all transactions on a https page via https even if it is trying to get the http version ? Or is my best bet to coding it in the PHP?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这实际上并不是服务器配置问题。您需要做的是确保服务器返回“https”作为所有外部资源(css、javascript 和图像)的位置。
使用通用头文件的最佳选择是使用相对 URL(不使用 http(s)://example.com/)并让浏览器确定应使用的协议。
如果 css 等位于不同的域中,那么我只需检测正在使用的协议并在 html 中修改该协议,然后再将其返回给用户。
或者您可以在任何地方使用 HTTPS ;0)
This isn't really a server configuration issue. What you need to do is ensure that the server is returning "https" for the location of all of your external resources (css, javascript & images).
Your best bet with a common header file is to use relative urls (no http(s)://example.com/) and let the browser determine the protocol that should be used.
If the css et al are on a different domain, then I'd just detect the protocol being used and massage the protocol in your html before returning it to the user.
Or you can just use HTTPS everywhere ;0)
只需从您的所有 URL 中删除 http: 即可。它将使用 http 或 https,具体取决于网页使用的协议。
Just remove http: from all your URL's. It will use http or https depending on what protocol the webpage is using.