Hey people. I see that this topic is repeated over and over on SO but I tried several solutions posted here and none of them worked quite for me. So basically - I know how to change specific pages on my website so that they're in https mode. However, I dunno how to rewrite the http requests that are INSIDE the code. So for example, if my page, say, payment.php, contains link that loads external ccs file like this -> http://example.com/somecss.css then google chrome will see it as dangerous link and display cross-red padlock next to site url. Now, I've tested it manually by changing all the http requests inside the code to https and the padlock magically became green so I guess I need some kind of mod rewrite rule that would rewrite all the links on those specific pages so that they would contain https. I hope I explained it well enough. Can anyone help me? I'm using codeigniter.
Asked
Active
Viewed 442 times
6
-
Check $_SERVER['HTTPS'] when you are building the URL's to local resources. – mikeds May 12 '11 at 15:06
2 Answers
3
To rewrite the http requests inside the code you have to use protocol-relative paths there.
<link rel="stylesheet" href="//www.domain.com/style.css">
<script src="//www.domain.com/script.js"></script>
It will automatically use the protocol of the parent page

Deepu S Nath
- 1,164
- 1
- 17
- 45
2
You have to make sure that the user is browsing your site over secure connection. You can redirect the user to secure connection (https://) using an .htaccess
file containing the following lines:
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]
Please, note that the .htaccess
should be located in the web site main folder.
In case you wish to force HTTPS for a particular folder you can use:
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} somefolder
RewriteRule ^(.*)$ https://www.domain.com/somefolder/$1 [R,L]
The .htaccess
file should be placed in the folder where you need to force HTTPS.

Deepu S Nath
- 1,164
- 1
- 17
- 45
-
yeah, I'm using this and it works fine, but it doesn't rewrite the http requests inside the code. – Pavel May 12 '11 at 11:35
-
6
-
7Yes, by using protocol-relative paths. For proper formatting, I posted it as an Answer instead of comment. Hope it helps :) Regards Deepu S Nath – Deepu S Nath May 12 '11 at 15:32