Understanding Absolute and Relative URL Addressing in Microsoft FrontPage

Microsoft FrontPage Visual Basic

Understanding Absolute and Relative URL Addressing in Microsoft FrontPage

Microsoft FrontPage uses absolute URL addressing. However, FrontPage does provide a way to change the addressing of URLs between absolute and relative addressing through the MakeRel and MakeAbs methods.

What is an absolute URL?

A URL defines the location of an object. When a URL is absolute, it defines unambiguously where the object is located. For example, http://www.microsoft.com/FrontPage/default.htm is the exact location of the welcome page for Microsoft FrontPage. The object, default.htm, is stored in the FrontPage folder or Web subsite on the Web server, www.microsoft.com.

A disk-based Web site that contains your Web sites on your hard drive might have a base absolute URL such as file:///C:/My Documents/My Web Sites, file:///C:/WINNT/Profiles/your logon alias/Personal/My Web Sites/index.htm, or file:///C:/Documents and Settings/your logon alias/My Documents/My Web Sites.

As Web sites are updated and the structure of a Web site evolves, documents can often be moved from one location to another in a Web site. If you're using a relative address, you may break some links. For example, if you have a document that has a hyperlink to an object, you can use an absolute URL to ensure that the hyperlink always refers to that object. For example, a document such as file:///C:/My Documents/My Webs/mydocument.htm, may contain an absolute URL that refers to the welcome page, http://www.microsoft.com/FrontPage/default.htm. If the document, default.htm, is moved to another location, the absolute URL for the document will always refer to the object on the Web server at www.microsoft.com in the subsite named FrontPage. If the URL for the hyperlink to default.htm is a relative address, the link could be broken if mydocument.htm is moved to a different subsite or main Web site.

What is a relative URL?

Instead of specifying every piece of a URL that fully defines how to find an object, you can abbreviate a URL to make it "relative" to a current location. Relative URLs are typically used when creating a Web site in which the pages in it refer to other pages on the site. A page such as file:///C:/My Documents/My Web Sites/mydocument.htm can have a relative URL to "newdocument.htm" or to "../My Web Sites2/default.htm". In these two cases, the referred addresses for these files are file:///C:/My Documents/My Web Sites/newdocument.htm and file:///C:/My Documents/My Web Sites2/default.htm. Notice that the full Web server or explicit directory isn't specified; the location is based on where the document is located.

Relative URLs are very useful, particularly when constructing a site in one place and then publishing it to another place. For example, you might not want to specify a server name while authoring a Web page, because the server name will change when the Web site is published.

How can an absolute URL be made relative?

URLs can be made relative either to a server or to a page. In order to make a URL relative to a folder or to a Web site, you need to make the URL relative either to a server or to a page, because FrontPage will treat the URL as if it were being made relative to a page in that folder or Web site. Each relative URL, combined with its base URL fully specifies where the object is located.

When you have an absolute address such as http://www.microsoft.com/mywebsite with an image file called MyPicture.gif residing in the images folder on the Web site, you can create a relative URL for that address by deciding whether the relative address will refer to a server or a page. For a server-relative URL, you'd use "mywebsite/images/MyPicture.gif" with the server name as the base for the relative URL, which fully defines the location of the object. For a page-relative URL, you'd use "images/MyPicture,gif" with the server name and the Web site name as the base for the relative URL, which fully defines the location of the object. For a folder-relative URL, you'd use "MyPicture.gif" with the server name, Web site name, and folder name as the base for the relative URL; this relative address fully defines the location of the object.

A folder-relative URL can also be specified from a different folder, for example, "../images/MyPicture.gif" could be used if the referring document were in another top-level folder on the same Web site and server. The ".." is the notation used to indicate up one folder level from the current URL address.

Programmatic Access to Relative URLs

Once you've decided whether to use server, Web site, or folder-relative URLs, you can determine which objects to use. For server or Web site-relative URLs, you would be working with methods related to the WebEx object. For folder-relative URLs, you would be working with methods related to the WebFolder object.

Converting relative and absolute URLs

Recommended use for FrontPage is absolute addressing. However, once you have specified a relative URL within FrontPage, you can use the MakeAbs method to convert it into an absolute URL. Similarly, if you have an absolute URL and you want to insert a reference into a document as a relative URL, you can use the MakeRel method to convert the address to a relative address. You can also use the MakeAbs and MakeRel methods to convert a hyperlink for a WebEx, WebFolder, WebFileEx, NavigationNode, or IHTMLDocument2 object.