Log in

View Full Version : Resolved hyperlink points to my root address when http is omitted



james438
07-23-2013, 01:42 PM
<a href='www.test.com'>test</a>

I was creating a hyperlink when I noticed that it pointed to http://www.mysite.com/test.com instead. I thought there might be something wrong with my formatting scripts, but it turns out it was because I was missing the http portion of the url.

Before I update my formatting script to auto correct and add the http if it is missing I was wondering why this was happening.

jscheuer1
07-23-2013, 02:52 PM
www.whatever.com is not a valid href, not in the sense in which it is obviously intended. It's interpreted as a file or folder name (either of which may contain . characters), and like any relative path is prepended automatically with the path to the current page.

If you want it to go to www.whatever.com, then the proper href to use is:

http://www.whatever.com/

Or:

https://www.whatever.com

Or even:

//www.whatever.com

In which case the browser will take the protocol of the current page (http: or https: or even file: if it's a local page not on a server, which is why this syntax is not used more often) and prepend that to it. This can be handy though if you have a template that is used by both http and https pages on your site and you want your off site link(s) to go to the corresponding type of layer on the external site, assuming they have both.

james438
07-23-2013, 06:49 PM
Ah, thanks. I believe when I first worked on web design I noticed this behavior and found that formatting it correctly took care of that, but never really learned why.