• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
redirect all http:// requests to https:// (SSL)

#11
[eluser]Kobus M[/eluser]
[quote author="niwa" date="1329215803"]thanks for the replies,
@robertotra and CroNiX both methods are working, all browsing url are forced in SSL, however,

there is still mixed content due to CSS background images.

Css is correctly loading from https in the browser :
Code:
<link type="text/css" rel="stylesheet" href="https://domain.com/css/main.css" media="screen" />

but inside it, background-image are still loading from http://

I use relative paths as in the CSS file such as :
Code:
background:url(../img/image.png)

Putting absolute paths could probably fix that, but isn't there a more elegant solution ? Absolute paths are hard to maintain as there are different production environments ...



[/quote]

You could look into less. lesscss.org, which allows you to use variables in CSS, where you can define the server base path as a variable in your CSS file.

This is untested, but should give you an idea.

Code:
@development: https://www.impero.co.za/test
@production: https://www.impero.co.za/
@switch: @development;

bg {
    background-image: url(@switch/images/background.png);
}

Hope this helps someone.

Kobus

#12
[eluser]@robertotra[/eluser]
For css background images, you can also parse css files as php files. In your .htaccess file add the following row before anything else:


Code:
AddType application/x-httpd-php .css

In this way your css file will be parsed by the php interpreter before they will be sent to the client and so you can use inside the css file:

Code:
background-image: url(<?php if (empty($_SERVER['HTTPS'])
     echo 'http://';
else
     echo 'https://';
?>yoursite/yourimage)

Bye
Roberto

P.S. This can be useful if you want to differentiate some other style features according to any $_SERVER variable

#13
[eluser]CroNiX[/eluser]
I think if you wrote your css urls like:

background: url(/images/myimage.jpg);

It will use the ssl if its on a secure page and regular if not.

#14
[eluser]niwa[/eluser]
thanks @robertotra and Cronix. It is now working correctly.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.