href to follow URL in broswers location bar - html

Suppose I had a URL in my browser location bar that read:
http://www.example.com/us/books
... how do I code the url in the page so that it'll add to the address in the location bar?
Example
Url in location bar: http://www.example.com/us/books
Url on page: Read more
Desired
http://www.example.com/us/books/this-title
No matter what I do, It wont appear after the entire URL. The URL isn't fixed.

This approach of using a relative path inside a reference does work. But you have to figure out some details which depend on your local situation.
In your case most likely the target url called is http://www.example.com/us/this-title (you did not tell us...). This is due to the fact how the browser (not the server!) interprets its current position inside the document hierarchy on the server.
If your base url reads http://www.example.com/us/books/ (note the trailing "/") then things would work as expected by you! You could even note the relative path as Read more. This works because the browser recognizes the current position as a folder and assumes the relative path to be located inside. This works for example when the html page holding that reference is delivered by an index document (index.html, index.php or similar) on the server. This is when the trailing slash makes sense, since it denotes that the current url retrieved the content of a folder, not a directoy.
Of course this is only what is happening on the client side. It might be that the server decides to rewrite the url and redirect the browser again. For example by using rewrite rules inside the http server. This is typically done to handle requests to non existing documents.

Related

Is the relative url in the source of a webpage supposed to be appended to the url of the webpage?

I am checking the source of a webpage whose url is
http://localhost:12345/web/query?name=time&
In the source of the html webpage, I saw a relative url:
Date
Is the relative url in the source supposed to be appended to the url of the webpage? In the above example, is it
http://localhost:12345/web/query?name=time&./query?name=time&params=3
Or is how to interpret the relative url in the webpage completely up to the author of the webpage?
When a web browser renders the webpage, the web browser interprets the relative url as
http://localhost:12345/web/query?name=time&params=3
I wonder how the browser can guess how the author interprets it.
Thanks.
./ is relative to the directory the file is in. I'd never use paths like that personally.
If the file is /web/query then Date and Date would essentially be the same thing. Obviously that link has to be found at the first level inside the /web directory or it wouldn't point to the right place, which is why I never use those type of paths, I always use paths that start at the document root, /.
These types of paths are usually found when developers either can't or don't know how to set up a proper web server for the site in my experience.

Html link rewriting angular js

In cases like the following, links are not rewritten; instead, the browser will perform a full page reload to the original link.
Links that contain target element
Example: link
Absolute links that go to a different domain
Example: link
Links starting with '/' that lead to a different base path when base is defined
Example: link
Can anybody help me with this.
angular docs? what is the meaning of this third point. i also dont understand the solution of normal application on the same directory
When running Angular in the root of a domain, along side perhaps a
normal application in the same directory, the "otherwise" route
handler will try to handle all the URLs, including ones that map to
static files.
To prevent this, you can set your base href for the app to and then prefix links to URLs that should be handled with ..
Now, links to locations, which are not to be routed by Angular, are
not prefixed with . and will not be intercepted by the otherwise rule
in your $routeProvider.

Absolute URL's acting like relative URL's

When I have a link like http://site.com, clicking it goes to that URL just fine.
But when the link is just www.site.com, it adds this URL to the parent website and consequently does not go to the URL.
So, clicking on <a href='www.site.com'>site</a> creates this in the browser taskbar: www.parentsite.com/www.site.com.
How can I fix this without using preg_replace? I am fairly new to this game.
Because www.parentsite.com is interpreted as a relative address, like for example index.htm, as opposed to an absolute URL which consists of protocol, hostname, and path.
When I'm on example.com's front page....
contact.html is a relative address, the absolute end result will be http://example.com/contact.html (the browser does this as an internal calculation)
images/ is a relative address, resulting in http://example.com/images/
www.xyz.com results in http://example.com/www.xyz.com
You need to prefix the protocol (eg. http://) to make the browser understand that you mean a full URL, and treat it accordingly.
Here's a background info article on the issue on MSDN.

Base URL for HTML and CSS

I got a question and although I could find related information, I'm if it was exactly about what I'm wondering about.
The thing is, I got a site on http://localhost/site.
Now, when I create a link, let's say, <a href="/posts">, it links to http://localhost/posts instead of http://localhost/site/posts.
It works fine if I remove the slash (<a href="posts">), that would be the closest and maybe the easiest solution, but I'd like to know why the links ignore the folder where the file is at?
And I also would like to know if this can be fixed with .htaccess or something.
I've read that a link that begins with / makes it "absolute". So a link beginning with / is only intended to be used to link directly to the root, or to be used by sites stored at the root (in this case it wouldn't make much sense?) ?
The leading '/' at the start of the URL informs the web browser that the path given is absolute (with respect to the web server root), i.e. if you link to /posts then you know that the resulting link will be to http://www.mysite.com/posts.
If you don't supply the leading '/' (and you don't give a complete url like http://www.mysite.com/posts) then usually the url is relative, and any page given will be relatvie to the page currently being viewed.
For example:
page being viewed link url target page
------------------------------------------------------------------------------
www.mysite.com/site link.html www.mysite.com/site/link.html
www.mysite.com/site ../link.html www.mysite.com/link.html
www.mysite.com/some/other/page link.html www.mysite.com/some/other/page/link.html
www.mysite.com/some/other/page ../../../link.html www.mysite.com/link.html
The decision on whether to use absolute or relative links is entirely up to you - the advantage of relative links is that if your site moves, links between pages on your site will still work correctly (for example if your site moves to www.mysite.com/otherpath, then any absolute links such www.mysite.com/originalpath/home will no longer work.
You should see the following site for a more complete explanation of relative urls:
Relative URLs (WebReference.com)
Your site root is localhost although you assume that site is your site root. When you use / it is relative to localhost as it is an absolute link.
Try doing it < a href="../posts" >
./ Means base directory, or home
../ Means one directory up

Urls treated as relative urls when using chrome-extension link?

I use chrome.extension.getURL for a file, and on the page it is placed, it treats it as a relative url (e.g. http://example.com/chrome-extension://ajs8dh8dsfauhdf8auhaffh/blah.js)
How can I make it treat it as an absolute URL instead? It is placed into the href component of a tag.
EDIT: I've seen people's plugins do this for CSS, so I know it is possible. Maybe not for href attributes?
chrome.extension.getURL should return a URL that starts with chrome-extension://. For example if you did chrome.extension.getURL("blah.js"); the value returned would be similar to "chrome-extension://ajs8dh8dsfauhdf8auhaffh/blah.js". This URL points to a local file stored in the extension's directory that is created when the extension is installed. The "ajs8dh8dsfauhdf8auhaffh" is a hash representing your extension to chrome. You're obviously getting something close to that, but the question is why is your's prefixed with "http://example.com/". I would check how you are setting the href attribute.