Search code examples
htmlhref

Using HTML href="" on section of URL string


I have a URL www.foo.com/bar/hello/world Can I use href= in such as way:

<a href = "/hello/world"> LinkText </a>

In other words, because of the versioning repository I use for work, only the sublink /hello/world of the final URL will the same when I push the site live.


Solution

  • For reference, see the docs

    However, in href, you can either use an absolute URL, such as https://www.foo.com/bar.html or, relative, something like /bar.html, where / refers to the webserver root (but not webserver's system root), or, you can use bar.html which points to a file in the same directory level.

    Basically you want to have a /hello/world link, it will point to www.foo.com/hello/world.

    If you want it www.foo.com/hello/world to point at www.foo.com/bar/hello/world, you can either rewrite the URL on the server, or, redirect the users to www.foo.com/bar/hello/world

    For URL rewriting, see your appropriate webserver docs