Phil
Phil

Reputation: 3055

Problems with links not working on local server

I'm trying to set up my site in Dreamweaver CS5 to work with my local server, and I'm having issues with document relative links.

I've got a structure on my HD like this

website
    _Common
         header.php
    _css
        twoColFixRtHdr.css
    index.php

and the same structure mirrored on my local WAMP server, except on the local server the site is in a subfolder, so it's something like www/website/

The problem is this line inside header.php

<link href="../_css/twoColFixRtHdr.css" rel="stylesheet" type="text/css" />

That looks correct to me pathwise, but on the local server it cannot find that css file from the header.php

If I change it to

<link href="/website/_css/twoColFixRtHdr.css" rel="stylesheet" type="text/css" />

or

<link href="_css/twoColFixRtHdr.css" rel="stylesheet" type="text/css" />

It works fine, but I want to use document relative links if I can, any ideas?

Upvotes: 0

Views: 278

Answers (3)

g_thom
g_thom

Reputation: 2810

If header.php is being included in index.php, the relative link ../_css/ in header.php won't work because index.php is at the same level as _css.

For all intents and purposes, once it's been included in index.php, to the browser, the content in header.php is now simply part of index.php, so all paths need to be relative to index.php.

Ie:

index.php

/my_include_folder - header.php

/_css - style.css

Once I add <?php include('my_include_folder/header.php); ?> to index.php, the links to css files, js, and hyperlinks in header.php should be relative to index.php.

Hopefully that makes sense.

Upvotes: 0

heximal
heximal

Reputation: 10517

you may achieve it by several ways. one of them: you can setup a VirtualHost (in httpd.conf) and point your subfolder as root folder for host.

Upvotes: 0

Sascha Galley
Sascha Galley

Reputation: 16101

This sounds clear to me, since I'm sure that you include the header file in the index.php file. So the path for the css files is set relatively to the index.php.

Upvotes: 2

Related Questions