Ssl – Apache: disable SSL for images, CSS and JS files

apache-2.2ssl

I am servicing some web pages over SSL.
The problem is that all the images, CSS and JS files are included on these pages using relatives paths (/images/save.png), thus the browser requests them on SSL. That's a bit of a waste.

Is there a way to configure Apache in order not to serve images, CSS and JS files over SSL, even if it is requested to?

Best Answer

I wouldn't recommend doing so since every client will receive a warning about the mixed ssl/non ssl content. But you asked:

RewriteEngine On
RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} !(\.js|\.css)$ [NC]
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI}

Update

As @lekensteyn pointed out correctly, this is a not to underestimate waste of resources. Rewriting is not really performing well in that situation. Also the RewriteConditions have to be matched for each and every request to the files.

You will also need more open TCP Ports, which again produces overhead. And even if we don't go into detail that much there will be a significant overhead for having two protocols doing ones' job.