Can I use htaccess to change http to https in image tags when needed?

Posted on 2007-10-18
Last Modified: 2012-06-27
I purchased a php script I'm using on a site.

I want to secure some of the pages (https).... however, in this rather complex script, all the images are absolute and point to http://www...  which causes a security warning saying parts of the page aren't secure.

Is there a way that I can use htaccess to change any reference to 'background="http://www.'  and 'img src="http://www.'   on the page to their https equivilents before the page is sent to the user?

If not, any other thoughts on this, other than rewriting the whole php script?


Question by:St_Aug_Beach_Bum

    Author Comment

    oh, I'm using Apache/1.3.27 (Unix)  (Red-Hat/Linux)  if that makes a difference....
    LVL 48

    Accepted Solution


    start the output-buffer with at the beginning of the https-page:

    <?php ob_start('makehttps'); ?>

    function makehttps($text) {
       $text = str_replace('background="http://www.', 'background="https://www.', $text);
       return $text;

    Rest will be done by php.

    Author Comment

    Cool :)

    Thank you,


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Suggested Solutions

    Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
    Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

    794 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now