在不更改 URL 的情况下显示另一个页面的内容


showing contents of another page without changing url

我已经有这样的页面了

http://example.com/page1
http://example.com/page2
http://example.com/page3

我需要在以下子域上加载这些页面

http://page1.example.com/
http://page2.example.com/
http://page3.example.com/

它应该像 http://page1.example.com/加载 http://example.com/page1 的内容一样工作,而无需更改浏览器地址栏中的URL

我使用了以下代码,但它更改了浏览器地址栏中的URL

header('Location: http://example.com/page1'); 

请帮忙。

试试这个。这是一种黑客:

// Just add the below few lines of code in your subdomain page - http://page1.example.com/
<?php
$content = file_get_contents('http://example.com/page1');
echo $content;
?>

让我知道这是否适合您。

<?php
include 'http://example.com/page1';
?>

这将导入页面的所有内容。如果多次调用 session_start(),也可以使用"include_once"而不是"include"。

同样地

<?php
require 'http://example.com/page1';
?>

如果未找到文件,"require"将停止加载页面的其余部分,而"include"不会停止加载。