WordPress.org

Ready to get started?Download WordPress

Forums

image source url problem - absolute to relative (2 posts)

  1. leoseccia
    Member
    Posted 3 years ago #

    Hi all,

    I have a WordPress site (hosted in IIS7) where all the images have an absolute url as source (in both the theme and in the content).

    Unfortunately this becomes a problem when the site is viewed over SSL/HTTPS. In IE, we get the Secure/Non Secure pop up and in all browser we don't get the reassuring lock in the address bar.

    Is there an easy way to change all the urls used to either: be relative or use the right protocol (ie. change http to https).

    Any help will be truly appreciated, whether it's a hack, an existing plugin or pointers on what to exploit when writing a plugin to solve this issue...

    Thanks.

    Leo

  2. leoseccia
    Member
    Posted 3 years ago #

    Hi all,

    I have found a simple solution to this...

    I created a simple plugin:

    <?php 
    
    /* Plugin Name: Content over SSL
    * Description: Swap to https if required
    * Author: Leo Seccia
    * Version: 1.0  */  
    
    add_filter('the_content', 'my_ssl');
    function my_ssl($content)
    {
      return (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == "on") ? ereg_replace("http://" . $_SERVER["SERVER_NAME"], "https://" . $_SERVER["SERVER_NAME"], $content) : $content;
    }
    ?>

    and then I also updated my wp-config.php:
    define('FORCE_SSL_ADMIN', true);

    All the best,

    Leo

Topic Closed

This topic has been closed to new replies.

About this Topic