Jump to content

Would this work use Media Server only on non-SSL pages


Mr S

Recommended Posts

What if i update the getMediaServer() function with && Tools::usingSecureMode() == false would this work?

        public static function getMediaServer($filename)
        {
                if (self::$_cache_nb_media_servers === null && Tools::usingSecureMode() == false)
                {
                        if (_MEDIA_SERVER_1_ == '')
                                self::$_cache_nb_media_servers = 0;
                        elseif (_MEDIA_SERVER_2_ == '')
                                self::$_cache_nb_media_servers = 1;
                        elseif (_MEDIA_SERVER_3_ == '')
                                self::$_cache_nb_media_servers = 2;
                        else
                                self::$_cache_nb_media_servers = 3;
                }

                if (self::$_cache_nb_media_servers && ($id_media_server = (abs(crc32($filename)) % self::$_cache_nb_media_servers + 1)))
                        return constant('_MEDIA_SERVER_'.$id_media_server.'_');

                return Tools::usingSecureMode() ? Tools::getShopDomainSSL() : Tools::getShopDomain();
        }
Link to comment
Share on other sites

  • 1 month later...

FYI: I manged to get it to work for me.
 
1)
edit override the function getMediaServer in file /override/classes/Tools.php
 
all I did was add "&& Tools::usingSecureMode() == false" to the if statement
 

	public static function getMediaServer($filename)
	{
		if (self::$_cache_nb_media_servers === null)
		{
			if (_MEDIA_SERVER_1_ == '')
				self::$_cache_nb_media_servers = 0;
			elseif (_MEDIA_SERVER_2_ == '')
				self::$_cache_nb_media_servers = 1;
			elseif (_MEDIA_SERVER_3_ == '')
				self::$_cache_nb_media_servers = 2;
			else
				self::$_cache_nb_media_servers = 3;
		}

		if (self::$_cache_nb_media_servers && Tools::usingSecureMode() == false && ($id_media_server = (abs(crc32($filename)) % self::$_cache_nb_media_servers + 1)))
			return constant('_MEDIA_SERVER_'.$id_media_server.'_');

		return Tools::usingSecureMode() ? Tools::getShopDomainSSL() : Tools::getShopDomain();
	}

 
2)
Backoffice > Advanced Parameters > Performance > Media servers
 
I have mydomain.net, mydomin.co, mydomain.biz in the Media servers setting
 
 
 
Now my media Servers only load on non SSL pages, because I don't have SSL for the other domains.
 

Link to comment
Share on other sites

Hello,

I followed this message because I have the same problem with CDN. I used 3 subdomains as CDN : cdn1.domaine.com, cdn2.domaine.com and cdn3.domaine.com.

When the page tries to load https or  httpshttpsI end up with an error because css files can't load. It's not really an error but my ssl page appears without css style !

Do you think it works with subdomains as CDN?

 

Thank you !

Link to comment
Share on other sites

It should work the same as long as your CDN sub-domains (or multi-domain setup) is already loading on non SSL pages.

 

The code above only disables media-server urls from being used by prestashop on all page request's made over https (ssl)

Link to comment
Share on other sites

Disregard this post the error was unrelated

If your backoffice Products is not loading you may have to edit your admin template file because PS Backoffice is trying to load the image from one of your Media Server over https (SSL).

Edit file: /admin/themes/default/template/controllers/products/informations.tpl


FIND:

<img src="{$image.src}" alt="{$image.legend}" />

REPLACE WITH:



<a href="{$image.src|replace:'https':'http'}" target="_blank">{$image.legend}</a>
Edited by HA!*!*Y (see edit history)
Link to comment
Share on other sites

  • 3 weeks later...

Thank you for response !

 

I'm trying to use your solution but i don't have a file "Tools.php" in /override/classes/ ! How can i do ? Edit the file in www/classes/Tools.php ?

 

EDIT 1 : I edited the file ine www/classes/Tools.php but i have one problem. On the pages contact-form.php and index.php.

 

When i'm loading this page on SSL, files in theme/mytheme/img can load because the filepath is https://cdn1.domaine.com/theme/mytheme/img/... Same thing on index.php, images can not be loaded.

Edited by presta'luv (see edit history)
Link to comment
Share on other sites

  • 3 years later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...