.htaccess redirect http to https with a different folder

Firelead

Affiliate Network
Mar 19, 2007
780
15
18
PA
www.firelead.com
I have a site that holds about 50 folders full of images, and inside of each folder are .gif and .jpg files. here is an example:

PHP:
http://domain.com/healthy/logo.gif
The folder name might change for each image. There are hundreds of images.

I'd like to be able to .htaccess redirect all those files to the shared hosting's SSL Wildcard URL so I can turn them into https files like so:
PHP:
https://secure.example.com/~username/domain/healthy/logo.gif

where ~username is my username on the shared hosting, domain is the previous domain name, healthy is the folder name, logo.gif is the file name
Can anyone help me with the code in htaccess for this?
I'm pretty sure it can be done, but it gets dicey with the redirection to a new URL while keeping the folder name, and inserting the domain name as a folder. Has anyone pulled off anything like this before?
 


No, I can't help you with the htaccess regex, but I've served http files as https before.

I've worked on https checkout pages where all of the content needed to be served over https or the browser would throw a message warning them about insecure elements. I created a simple php script like
Code:
readfile( $_GET['url'] );
and hosted that script someplace accessible via https.

On the checkout page rather than referencing "http://test.com/cc.jpg" I reference "https://securetest.com/script.php?url=test.com/cc.jpg".

There is a slowdown factor because the script has to fetch the remote file before it can output it, and readfile is slower than direct file access through the webserver. However, for my uses it has not been noticeable.

You'd also want to put in some checks to prevent injection and people using your script/SSL cert for their own images. Perhaps an id-based system rather than passing the URL itself.

Vad
 
vadim, thank you for that-- but I figured it out... I was messing around with the Redirects area in cpanel and was able to setup a solution. It setup regex without writing it.