Reputation: 6365
How do you make a Href follow the URL in the address bar?
For example : If the URL in the address bar is http://www.example.com/us
and my href
is href='/books'
, on clicking the link, the link leads to http://www.example.com/books
and not http://www.example.com/us/books
. How do I code the href to do this? I tried several methods, but unless I code it as href='/us/books'
it will not work as expected.
Upvotes: 0
Views: 630
Reputation: 1931
There are a few different ways in which to do this, depending on the server configuration you're running your site on. The only sure way to do this in pure HTML is
<a href="/us/books/">Books</a>
Because URL links are resolved on the client side, and other configurations would complicate things (i.e. IIS Virtual applications)
If you're using ASP for a virtual application, try this:
<a href="<% Response.Write(Server.MapPath("~")); %>/Books">Books</a>
For other configurations, like PHP you could set a global constant like
define("US_ROOT_DIR", "/us");
And use it as
<a href="<?php echo US_ROOT_DIR; ?>/Books">Books</a>
But in the end, it really comes down to directory structure management since every project is different. Any way I hope this helps and if not I hope it points you in the right direction.
Upvotes: 1
Reputation: 91
You can use this:
<head>
<base href="http://www.example.com/us">
</head>
then href="/books"
will redirect to href="http://www.example.com/us/books"
Upvotes: 1