Formatting Relative URLs RRS feed

  • Question

  • User-1593004730 posted

    Greetings Folks,

    It's been a while since I've posted. I've been out of web design for a couple years.

    I have a question regarding relative URLs. Links on pages on my hosting server work when formatted as relative URLs as in the two methods below:

    <a href="contacts.htm"> - without forward slash
    <a href="/contacts.htm"> - with forward slash

    As a rule of thumb, should the forward slash be there or not?

    Thanks in advance for you help.

    Wednesday, January 22, 2020 5:34 PM

All replies

  • User281315223 posted

    These should both resolve to the same canonical URL since a single leading slash is considered by the spec to be an absolute URL, so it's likely going to be more a matter of preference:

    A relative reference that begins with a single slash character is termed an absolute-path reference. A relative reference that does not begin with a slash character is termed a relative-path reference.

    You can see a more in-depth discussion here, but you'll likely want to just ensure you are being consistent in whichever approach you decide to take.

    Wednesday, January 22, 2020 5:54 PM
  • User665608656 posted

    Hi hypercode,

    Whether you need to add a forward slash depends entirely on whether your current page and contacts.htm page are in the same folder.

    If they belong to the same folder side by side, then you do not need to add a forward slash, but if the two files are in different below the folder level, you need to modify the path of the href.

    You can refer to this link for more details: HTML File Paths

    If your files are in the same project, there is a quick way in vs to determine the path you need to reference the file, you can directly drag the file you need (such as the contacts.htm page here) with the mouse move to your current front page, then it will automatically generate a relative path.

    Best Regards,


    Thursday, January 23, 2020 3:32 AM