Specify a Root Path of your HTML directory for script links?

I'm writing a template for dreamweaver, and don't want to change the scripts for subfolder pages.

Is there a way to make the path relative to the root directory?

for example:

<link type="text/css" rel="stylesheet" href="**root**/style.css" />

Instead of **root** above, I want a default path there. Is there any way to do anything like this?


Solution 1:

To be relative to the root directory, just start the URI with a /

<link type="text/css" rel="stylesheet" href="/style.css" />
<script src="/script.js" type="text/javascript"></script>

Solution 2:

I recommend using the HTML <base> element:

<head>
    <base href="http://www.example.com/default/">
    <link rel="stylesheet" href="style.css" />
    <script src="script.js"></script>
</head>

In this example, the stylesheet is located in http://www.example.com/default/style.css, the script in http://www.example.com/default/script.js. The advantage of <base> over / is that it is more flexible. Your whole website can be located in a subdirectory of a domain, and you can easily alter the default directory of your website.