一个阿里主机如何实现绑定多个域名加载不同页面-经验交流论坛-轻友天地-轻论坛

一个阿里主机如何实现绑定多个域名加载不同页面

众所周知域名在阿里云备案,需要解析到阿里主机或服务器,阿里云的服务器又不便宜只有新用户才便宜,又不想域名掉备案又不想花重金在阿里买服务器怎么搞呢?

买阿里云的主机,但是有多个域名一个主机怎么实现加载不同的内容呢,今天这个代码是通过ChatGPT做出来的。

1.实现了三个域名加载不同的内容。对应域名加载对应HTML。

2.请注意,在实际使用时,需要根据实际情况进行修改和适当的调整。

3.首先在虚拟机根目录创建一个index.php和三个html并命名为域名前缀。

4.复制下面代码到index.php文件中,并修改文件中的域名为自己的。

<?php
 
$host = $_SERVER['HTTP_HOST'];
 
switch ($host) {
    case 'www.qingluntan1.cn':
        // 加载 qingluntan1.html 页面
        include 'qingluntan1.html';
        break;
    case 'www.qingluntan2.cn':
        // 加载 qingluntan2.html 页面
        include 'qingluntan2.html';
        break;
    case 'www.qingluntan3.cn':
        // 加载 qingluntan3.html 页面
        include 'qingluntan3.html';
        break;
    default:
        // 默认情况下返回一个 404 页面
        header('HTTP/1.1 404 Not Found');
        echo '<html><body>';
        echo '<h1>404 Not Found</h1>';
        echo '<p>The requested URL ' . $_SERVER['REQUEST_URI'] . ' was not found on this server.</p>';
        echo '</body></html>';
        break;
}

 

请登录后发表评论

    没有回复内容


Warning: error_log(/www/wwwroot/www.qingluntan.cn/wp-content/plugins/spider-analyser/#log/log-3019.txt): failed to open stream: No such file or directory in /www/wwwroot/www.qingluntan.cn/wp-content/plugins/spider-analyser/spider.class.php on line 2900