8

I'm trying to set a local site-root using the base tag. The following code isn't working. Am I doing something wrong? How do I set the mysite folder as base?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
  <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
      <base href="file:///home/me/mysite"></base>
      <title> Asset Take On Process </title>
      <meta http-equiv="content-type" content="text/html; charset=UTF-8" /> 
      <link rel="stylesheet" type="text/css" href="/css/main.css" />
    </head>
    <body>
      some stuff
    </body>
  </html>

The site folder structure is

mysite
   |___css
   |___img
   |___js

and so on..

When I load the web-page it doesn't see the main.css in the css folder at all.

Tahnoon Pasha
  • 5,848
  • 14
  • 49
  • 75

3 Answers3

6

If you remove that /, it should make it relative off the current path, which, when a base tag is present would be

http://localhost/website/.

You will also need to add a trailing / to the end of the href, to indicate that it's a folder.

Full working example:

<!doctype html>
<html>
<head>
<base href="/test/" />
<script src="assets/test.js"></script>
<body>
hi
</body>
</html>
  • Actually depending on who you ask, it's still relative since it is relative off the current domain. But I prefer to call this absolute since it's signifying the path is from the root, based on the current domain. Although, I guess technically that makes it relative in the grand scheme of things, and absolute only in terms of the current domain. Whatever.

kindly refer this link

http://social.msdn.microsoft.com/Forums/ie/en-US/c51bb8b9-40ab-437b-a125-88b660f3e1ca/ie8-base-tag-issues

backtrack
  • 7,996
  • 5
  • 52
  • 99
  • 1
    A URL with `http://localhost` is quite different from the `file://` URL in the question. (To begin with, the latter does not require any HTTP server in the local computer.) – Jukka K. Korpela Aug 26 '13 at 10:57
  • 1
    I generally refer to /myResource/file.ext as "relative to root" – zedd45 Jan 27 '14 at 03:54
6

A correct tag would be

<base href="file:///home/me/mysite/"/>

if you wish to set file:///home/me/mysite/ as the base address, so that e.g. css/main.css refers to file:///home/me/mysite/css/main.css. Note the importance of the slashes. In an href value in base, anything after the last slash is ignored: file:///home/me/mysite means the same as file:///home/me/ there.

This is a confusing topic, and it is further confused by some browsers’ implementation that may support relative URLs in the value; by the specifications, only absolute URLs are permitted.

There is normally no reason to use the base element. Relative URLs such as css/main.css or ../css/main.css work just fine, specifying addresses as relative to the address of the HTML page. This means that they need not be changed if the site is uploaded onto a server.

Jukka K. Korpela
  • 195,524
  • 37
  • 270
  • 390
  • thanks @JukkaK.Korpela please see my follow on question describing the issue I'm having with relative paths here http://stackoverflow.com/questions/18442958/using-a-relative-url-scheme-effectively . This is a useful answer however. – Tahnoon Pasha Aug 26 '13 at 11:26
5

Just to clarify the other answers:

The base tag must end in a slash. The following URL's must not begin with slashes:

It's logical, because adding them together makes a complete address. But it's counterintuitive because we're used to using /images/image.jpg to make things work everywhere.

Andy Swift
  • 2,179
  • 3
  • 32
  • 53