views:

543

answers:

3

I have a PHP file at my server root.. index.php .. which include's .. DIR/main.php

Now .. DIR/main.php .. has relative links to many nearby files.

All the relative links are broken.


Any way I can change the relative-URL base path for links?

... so the included content of DIR/main.php has all its links to friend1.php changed to DIR/friend1.php.


Edit: This in NOT about include's, this is about CHANGING ahref links en-masse.

+1  A: 

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.

tkotitan
+1  A: 

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.

rojoca
+1  A: 

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

kalyanji