简体   繁体   English

如何添加到php get home url中以链接到新页面?

[英]How to add to php get home url to make links to new pages?

I'm currently working on a website that's hosted on our development server, I want to make some links that won't break when I move the site onto the new domain, so I plan to use to first get the root url, but how can I use that to make a link to the page at www.domain.com/blog? 我目前正在开发服务器上托管的网站上工作,我想建立一些在将网站移至新域时不会中断的链接,因此我打算先获取根网址,但如何使用我可以用它来链接到www.domain.com/blog上的页面吗?

Thanks a lot, hope that makes sense, couldn't really find a better way to word it! 非常感谢,希望如此,并不能真正找到更好的措辞方式!

Thanks, Ethan 谢谢,伊桑

You can either use relative paths or $_SERVER['HTTP_HOST']; 您可以使用相对路径,也可以使用$_SERVER['HTTP_HOST'];
For example : 例如 :

$baseUrl = "http://" . $_SERVER['HTTP_HOST'];
$myLink = $baseUrl."/mypage";

Define in a common script like db.php / config.php 用db.php / config.php之类的通用脚本进行定义

$application = 'local';
//$application = 'web';

if($application == 'local'){
    define("SITEROOT","localhost/domain.com/");
    $websitelink = "http://".constant("SITEROOT");
}
if($application == 'web'){
    define("SITEROOT","www.domain.com/");
    $websitelink = "http://".constant("SITEROOT");
}

Now in your menubar or where you want to add link to any page..eg for blog.. 现在,在菜单栏中或您要在其中添加任何页面链接的位置。例如,博客。

<a href="<?php echo $websitelink;?>blog">Go To Blog</a>
<a href="<?php echo $websitelink;?>forum">Go To Forum</a>
<a href="<?php echo $websitelink;?>aboutus.php">About Us</a>

When you go online , simply disable $application = 'local' and comment out $application='web' like below 当您上网时,只需禁用$application = 'local'并注释掉$application='web'如下所示

//$application = 'local';
$application = 'web';

With this approach, you can define many parameters and can use them anywhere in website....Just changing $application does the trick... 通过这种方法,您可以定义许多参数,并可以在网站的任何位置使用它们。...只需更改$application问题...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM