1

I have an include file, lets say inc-navigation.html, that has absolute paths (http://www.pathtoimage.com/image.com) that are on EVERY PAGE. Well, using SSL, I can't use that same include file because it is not referencing https:// What a pain!

SO, I was maybe thinking of using htaccess to do a url rewrite of all references of HTTP to HTTPS when the browser requests a https page. Again, just to be clear, I don't want to "redirect", just "replace".

So, I have this:

RewriteCond %{HTTPS} !=on 
RewriteRule ^http$ https

But it doesn't seem to be working. Is this type of thing even possible?

3 Answers 3

1

HTTPS is HTTP over SSL/TLS, which secures the transport layer, that is, the communication between the browser and the web server.

mod_rewrite rewrites requests internally or externally via redirects, but only once the request has been sent by the browser, which is too late in your case.

If you want to use your content normally hosted on plain HTTP via an HTTPS connection, you could set up a reverse proxy from the HTTPS host to the plain HTTP host. mod_proxy_http, which is bundled by default with Apache 2.x, would be able to rewrite Location headers in redirect, but not the content of the pages themselves (and their links). To do so, you may have to look at mod_proxy_html, which should be able to rewrite the links within the pages themselves.

This being said, having absolute links in your inc-navigation.html file sounds like a design mistake, it may be easier to do a search/replace to get rid of these absolute links in that file than setting up mod_proxy_html.

If some of the absolute links you're using point to other hosts, you may be able to use network-path relative references (starting with //, thus making the scheme relative). This would only work of course if these hosts are HTTPS-enabled.

1
  • completely understand. I remember about 3 months ago, I used single slash URLs and if I remember right, the xml-sitemaps.com sitemap generator flagged those as broken links. Not exactly sure WHY, but as soon as I made them absolute, it didn't complain anymore. At any rate, I will switch to those and see what happens! I appreciate the help.
    – PaulHanak
    Sep 4, 2012 at 1:39
1

You can't do this because you need the visitor's web browser to understand that it should be using a secure (https) connection to fetch these items, and that's not possible if you hide the new location from the visitor (which is what you do when you use RewriteRule without a redirect).

I think your best bet is to change the include file to use absolute paths which do not specify a domain or protocol. In other words, in the include file change:

http://www.domainname.com/path/to/image/image.png

to

/path/to/image/image.png

everywhere such a pattern occurs.

4
  • This would work perfectly, but then you run into the problem of subdirectories, correct? the /path/to/image varies depending on what subdirectory the user is in....
    – PaulHanak
    Sep 3, 2012 at 19:31
  • @PaulHanak, you seem to be getting confused between absolute-path references and relative-path references, both of which are relative references. See tools.ietf.org/html/rfc3986#section-4.2
    – Bruno
    Sep 3, 2012 at 20:00
  • @Bruno, ok now you REALLY confused me! hahaha. So you are saying that both domainname.com/path/to/image/image.png and /path/to/image/image.png are both actually relative references? Interesting! I always learned the opposite. :) At any rate, when I use the later though, there are various crawlers that now identify the image.png as a broken image since it is not "absolute" ... hehe. Any thoughts on combatting that?
    – PaulHanak
    Sep 3, 2012 at 22:17
  • @PaulHanak. Not sure whether the comment markup made the links automatically (use back-quotes if needed) in your comment. I'm saying that http://example.com/path/image.png is absolute, but path/image.png, /path/image.png and //example.com/path/image.png are relative references. Not sure how crawlers support //example.com/... but they should easily support the others.
    – Bruno
    Sep 3, 2012 at 22:21
0

You have syntax slightly wrong, here is what you need

 RewriteCond %{HTTPS} !on [NC]
    RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
1
  • Hmm this doesn't seem to work either. This is redirecting EVERY URL that is loaded with http:// to a https://. My goal is to switch every http to https ONLY if the URL is already SET to https:// . Does that make sense? LOL! I've gone crosseyed...
    – PaulHanak
    Sep 3, 2012 at 19:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .