Jump to content

change images Base URL


Ehsanai

Recommended Posts

Hi,

I create a clone of my website and I need to use images on first site for second site. I just found a solution to change images base URL by classes/link.php -> function -> getImageLink

I add this:

 

$newDomain = "https://images.firstsitedomain.com";

 

and change the __PS_BASE_URI__ to  $newDomain

 

 

// Replace with your chosen domain

$newDomain = "https://images.yourdomain.com";

if ($this->allow == 1 && !$notDefault) {

$uriPath = $newDomain . $ids . ($type ? '-' . $type : '') . $theme . '/' . $name . '.jpg'; }

else  {

$uriPath = $newDomain . _THEME_PROD_DIR_ . $ids . ($type ? '-' . $type : '') . $theme . '.jpg'; }

 

but not working carefully and image url is like this:

seconddomainsitehttps://images.firstsitedomain.com/3213-large.....

 

if you have any idea, please help me on this.

 

Link to comment
Share on other sites

  • 3 weeks later...
On 4/2/2024 at 11:44 PM, Ehsanai said:

Hi,

I create a clone of my website and I need to use images on first site for second site. I just found a solution to change images base URL by classes/link.php -> function -> getImageLink

I add this:

 

$newDomain = "https://images.firstsitedomain.com/Dog likes best";

 

and change the __PS_BASE_URI__ to  $newDomain

 

 

// Replace with your chosen domain

$newDomain = "https://images.yourdomain.com";

if ($this->allow == 1 && !$notDefault) {

$uriPath = $newDomain . $ids . ($type ? '-' . $type : '') . $theme . '/' . $name . '.jpg'; }

else  {

$uriPath = $newDomain . _THEME_PROD_DIR_ . $ids . ($type ? '-' . $type : '') . $theme . '.jpg'; }

 

but not working carefully and image url is like this:

seconddomainsitehttps://images.firstsitedomain.com/3213-large.....

 

if you have any idea, please help me on this.

 

Hello,

It looks like you’re trying to dynamically change the base URL for your images when cloning your website. The issue you’re encountering where the domain name is appended incorrectly suggests there might be a concatenation problem in your PHP code.

Here’s a revised version of your code snippet that should correctly change the base URL for your images:

$newDomain = "https://images.firstsitedomain.com";

// Use this variable to check if the script should use the new domain
$useNewDomain = true;

if ($this->allow == 1 && !$notDefault) {
    // Check if the new domain should be used
    if ($useNewDomain) {
        $uriPath = $newDomain . '/' . $ids . ($type ? '-' . $type : '') . $theme . '/' . $name . '.jpg';
    } else {
        // Fallback to the original path if the new domain shouldn't be used
        $uriPath = __PS_BASE_URI__ . $ids . ($type ? '-' . $type : '') . $theme . '/' . $name . '.jpg';
    }
} else {
    if ($useNewDomain) {
        $uriPath = $newDomain . _THEME_PROD_DIR_ . '/' . $ids . ($type ? '-' . $type : '') . $theme . '.jpg';
    } else {
        $uriPath = __PS_BASE_URI__ . _THEME_PROD_DIR_ . '/' . $ids . ($type ? '-' . $type : '') . $theme . '.jpg';
    }
}

Make sure to replace https://images.firstsitedomain.com with the actual domain you want to use for your images. The $useNewDomain variable is a flag that allows you to toggle between the original and new domain paths easily.

Also, ensure that __PS_BASE_URI__ and _THEME_PROD_DIR_ are defined correctly in your configuration and that they do not already contain a trailing slash, as this could result in double slashes in your URLs.

I hope the information may helps you. 

 

 

Edited by Graham Rodriguez (see edit history)
Link to comment
Share on other sites

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...