Web development - relative URLs without duplicating files

Posted by eshriek on Stack Overflow See other posts from Stack Overflow or by eshriek
Published on 2011-01-14T11:42:50Z Indexed on 2011/01/14 13:53 UTC
Read the original article Hit count: 231

I have a site with index.php in the root folder, images in /img , and overview.php in /content . I have a sidebar.php file that is included in both index.php and overview.php . How should I refer to /img/image.gif if I include a link in each file? The location of image.gif changes relative to the location of the file that references it. Using /img/image.gif in sidebar.php will work in index.php, but it fails for the file located at /content/overview.php. The only solution that I can see is to either include a seperate sidebar.php in each subdirectory, or include an /img directory in every sub-directory. The best suggestion that I can find is to use the <base> html tag as suggested here: Change relative link paths for included content in PHP

However, in the same link, SamGoody suggests that the <base> tag "is no longer properly supported in Internet Explorer, since version 7."

I'd like some insight on the matter before committing to a course of action.

Thanks.

EDIT: I am using the wrong approach below with "../"

Example-
root/index.php:
...
<link rel="stylesheet" type="text/css" href="style.css" />
<title>title</title>
</head>
<body>
<?php include('include/header.php'); ?>
<?php include('include/menu.php'); ?>

...

root/include/header.php:
...
<div id="header">
<span class="fl"><img src="img/dun1.png"/></span><span class="fr"><img src="img/dun2.png"/></span>

...

root/content/overview.php:
...
<link rel="stylesheet" type="text/css" href="../style.css" media="screen" />
<title>Overview</title>
</head>
<body>
<?php include('../include/header.php'); ?> <?php include('../include/menu.php'); ?>

...

© Stack Overflow or respective owner

Related posts about php

Related posts about web-development