如何运用php根据网址域名来路判断跳转呢?
这里搜集下相关代码:
1、 问题要求:
根据来路分别跳转
根据输入域名跳转不同页面
立即学习“PHP免费学习笔记(深入)”;
PS:前提是不使用域名解析中的 URL转发!
实例: 访客输入:www.abc.com 访问根目录下 index.html访客输入:www.123.com 访问根目录下 main.html
可在原默认主页代码前加上如下判断语句
<p><?php </p><p>$sUrl = $_SERVER['SERVER_NAME'];</p>
<div class="aritcle_card">
<a class="aritcle_card_img" href="/ai/1549">
<img src="https://img.php.cn/upload/ai_manual/000/969/633/68b7a0dc42b0b527.png" alt="Felvin">
</a>
<div class="aritcle_card_info">
<a href="/ai/1549">Felvin</a>
<p>AI无代码市场,只需一个提示快速构建应用程序</p>
<div class="">
<img src="/static/images/card_xiazai.png" alt="Felvin">
<span>161</span>
</div>
</div>
<a href="/ai/1549" class="aritcle_card_btn">
<span>查看详情</span>
<img src="/static/images/cardxiayige-3.png" alt="Felvin">
</a>
</div>
<p>if ($sUrl=="www.abc.com"){ </p><p>echo '<meta http-equiv="refresh" content="0; url=http://www.abc.com/index.html">';</p><p>}</p><p>if ($sUrl=="www.123.com"){ </p><p>echo '<meta http-equiv="refresh" content="0; url=http://www.123.com/main.html">';</p><p>}</p><p>?></p><p>可根据自己实际要求来灵活变化语句!
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号