简体   繁体   English

如何使用.htaccess或PHP使所有HTTP请求通过HTTPS

[英]How to make all HTTP requests go through HTTPS using .htaccess or 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. 好的,这是我的问题,我有一个通过https传送的文件,服务器上的所有文件都有一个公共的header.php文件,该文件包含在文件中。 In the header file i have all my stylesheets etc called from my cdn folder. 在头文件中,我从CDN文件夹中调用了所有样式表等。 http://cdn.domain.com since they are called http in my https file (via header.php) it doesnt transmit fully in https. http://cdn.domain.com,因为它们在我的https文件(通过header.php)中称为http,因此在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 ? 有没有办法让htaccess通过https在https页面上进行所有交易,即使它试图获取http版本也是如此? Or is my best bet to coding it in the PHP? 还是我最好的选择是在PHP中编码?

Thanks 谢谢

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). 您需要做的是确保服务器为所有外部资源(css,javascript和图像)的位置返回“ https”。

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. 使用通用头文件的最佳选择是使用相对URL(没有http(s)://example.com/),然后让浏览器确定应使用的协议。

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. 如果css等人位于不同的域中,那么我只需要检测所使用的协议并在将其返回给用户之前在html中对其进行按摩即可。

Or you can just use HTTPS everywhere ;0) 或者,您可以随处使用HTTPS; 0)

Just remove http: from all your URL's. 只需从您所有的URL中删除http:。 It will use http or https depending on what protocol the webpage is using. 根据网页使用的协议,它将使用http或https。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM