Change relative link paths for included content in PHP

六月ゝ 毕业季﹏ 提交于 2019-12-02 07:37:12

The base tag in html works for relative links. See w3schools for an example on how to use it.

Assuming main.php is a mix of HTML and PHP then when you output a link you'll need to include a prefix:

<a href="<?php echo $web_root; ?>relative/path/">relative link</a>

Where $web_root is your root path ('DIR'). Probably a good idea to define it in a separate include file so you only have to define it once for all your scripts.

The picture isn't too clear but you can probably rearrange a few files and use symlinks to solve the problem.

For your example, you could make a symlink DIR/friend1.php that points to /friend1.php, but you would have to do this for all your files, or just move them.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!