Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

URL without "http|https"

Tags:

http

url

https

I just learned from a colleague that omitting the "http | https" part of a URL in a link will make that URL use whatever scheme the page it's on uses.

So for example, if my page is accessed at http://www.example.com and I have a link (notice the '//' at the front):

<a href="//www.google.com">Google</a> 

That link will go to http://www.google.com.

But if I access the page at https://www.example.com with the same link, it will go to https://www.google.com

I wanted to look online for more information about this, but I'm having trouble thinking of a good search phrase. If I search for "URLs without HTTP" the pages returned are about urls with this form: "www.example.com", which is not what I'm looking for.

Would you call that a schemeless URL? A protocol-less URL?

Does this work in all browsers? I tested it in FF and IE 8 and it worked in both. Is this part of a standard, or should I test more browsers?

like image 492
topher-j Avatar asked Feb 06 '12 14:02

topher-j


People also ask

How do I make a link without HTTP?

You can link to "example.com", example.com, example.com or just //example.com. The latter stating that you should use your current client's protocol (usually a browser http/https, but could be an email client, etc.) and is extremely useful when you consider a site having both http and https protocols running.

Can you have a website without HTTP?

HTTP, or Hypertext Transfer Protocol, is a common sight in web browsers everywhere. HTTP helps web browsers to understand the data that is being delivered to them by servers. Without HTTP, we wouldn't expect such communication to exist – we'd not be able to browse the web.

Do you need to include HTTP in link?

You don't need to include the protocol (the browser uses HTTP by default) or the port (which is only required when the targeted Web server is using some unusual port), but all the other parts of the URL are necessary.

Do you need https in href?

So yes you need to put http, https, or www, just to let browser know that you redirecting user somewhere outside of this site(server), or it will try to find path you specified on current server. It is because each link is just a path to some document and protocol explicitly says that it is other server.


1 Answers

Protocol relative URL

You may receive unusual security warnings in some browsers.

See also, Wikipedia Protocol-relative URLs for a brief definition.

At one time, it was recommended; but going forward, it should be avoided.

See also the Stack Overflow question Why use protocol-relative URLs at all?.

like image 176
Mark Maruska Avatar answered Sep 20 '22 05:09

Mark Maruska