V
V
Vitaly Mironov2019-01-14 08:51:00
PHP
Vitaly Mironov, 2019-01-14 08:51:00

How to load the content of another site in your own?

I decided to make a multi-regional site. In order not to make separate sites and fill them one by one, I decided to make one main site, and subdomains will load it by passing the get parameter - city. After that, depending on the city, different SEO text will be displayed on the main site. Everything else is identical. The site loads normally, but when you click on the links, it leaves the subdomain. How to avoid it?
Here is the code, all examples are working:

<?php

$domen = "http://sd-multi.ru";
$city = "vlad";

// 3 способ 
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $domen);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($ch);
curl_close($ch);
echo $data;

// 1 способ
echo file_get_contents($domen);

// 2 способ
$array = file($domen);
foreach ($array as $line) {
  echo $line;
}

// 4 способ
$fp = fopen($domen, "r"); 
while(!feof($fp)) { 
  echo fread($fp, 1); 
} 
fclose($fp);

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Anton, 2019-01-14
@nor1m

I decided to make a multi-regional site.

Create a subdomain, direct it to the main site, write a functional that takes the name of the subdomain, no getas are needed, and based on the selected subdomain, substitute dynamic data, SEO text, meta tags, etc.
And, yes, there should be relative paths on the site.

K
Konstantin B., 2019-01-14
@Kostik_1993

First, why is all this in PHP? There is also Nginx. It is faster and more productive))
Make all links on the main site relative, if it is not possible, do it in Nginx during proxying

L
Lander, 2019-01-14
@usdglander

Replace all absolute paths in the resulting html with relative ones
echo str_replace($domen, '', $data);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question