22

I just added an SSL to my site. When I go to https://mydomain.com I see the text but no CSS or images are there. It is on a dedicated server and I have a full control of the code.

All paths currently are relative. I can view images and css when I go to those files directly whether using HTTP or HTTPS. But when i load a page they are not loading...

When I use Firebug and look in NET, I see for each image 302 Found. What does that mean?

What changes do I need to make to make sure http and https display site similarly?

Do I make all paths absolute? Is there a way to make a single change to affect all or I actually have to go and change each and every one?

Thanks.

4 Answers 4

11

Do you have hotlink protection? If you have try to disable it. And see if it helps.

2
  • 1
    Instead of disabling it you could write (in your htaccess) something like this : RewriteCond %{HTTP_REFERER} ^http(s)?://(www\.)?XXX.com Feb 9, 2016 at 16:45
  • 5
    What is hotlink protection? Mar 4, 2017 at 18:47
3

You don't need to make everything absolute, but you need to make sure that your CSS and images are accessible over SSL. Try accessing them directly, or use Firebug or a similar browser tool to figure out where it's trying to load them from. Consider using "Protocol-relative URLs" so that CSS, images, and such are always accessed using the same protocol (http or https) as the page itself. http://paulirish.com/2010/the-protocol-relative-url/

1
  • I can see my images and CSS with both HTTP and HTTPS but obviously they do not load. Also when I go to my HTTPS page and view source in FF and then click on a CSS link it takes me to HTTP... But if I click on a link, while on HTTPS page it loads another page as HTTPS. I'm a bit confused.
    – santa
    Oct 27, 2011 at 16:13
2

If you are pointing at your CSS with an absolute link (like http://www.yourcompany.net/yourcompany.css) it will not show the CSS in https. If you make that absolute https://www.yourcompany.net/yourcompany.css, it will work in both calls.

1

I had the same issue. If page is opened in https then css/js should also be loaded in https. By this I mean, to load css/js it should use the same protocol as it used for opening html/jsp/jsf etc page. So the solution is to not use absolute url for css/js. Use relative url instead like this :

<link type="text/css" rel="stylesheet" href="../css/style.css" />

OR use this :

<% String contextPath=request.getScheme()+"://"+request.getServerName()"+":"+request.getServerPort()+request.getContextPath();

<link type="text/css" rel="stylesheet" href="<%=contextPath>/css/style.css" />

This should solve image loading issue.

1
  • You can use a double forward slash to indicate absolute but with same protocol: such as "//css/myfile.css".
    – nickdnk
    Sep 28, 2015 at 18:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.