473,574 Members | 2,777 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

relative URLs: OK to omit "http:"?

After doing a websearch, it appears that it's OK to omit the "http:" to form
a relative URL. Are there any pitfalls to this?

For example, if there is a page
http://www.domain1.com/page1.html
with a link to
http://www.domain2.com/page2.html
you can abbreviate the second link as
//www.domain2.com/page2.html

What I'm wondering is if there are any drawbacks to this. (One that I can
think of is that if someone saves the HTML page to their hard disk, the link
won't work anymore since the URL is relative to the document as on the
website, not as on their harddrive.)

Also, I just tried it and it seems that clicking on the link after the page
has been saved to the hard drive crashes IE 6.0.


Jul 20 '05 #1
24 4468
sinister wrote:
After doing a websearch, it appears that it's OK to omit the "http:" to form
a relative URL. Are there any pitfalls to this?

It is not correct usage of the href attribute:
<http://www.w3.org/TR/REC-html40/struct/links.html#h-12.> It should
contain an URI: <http://www.w3.org/TR/REC-html40/types.html#type-uri>

Your example is _not_ a valid URI.
--
Anne van Kesteren
http://www.annevankesteren.nl/
Jul 20 '05 #2
"sinister" <si******@nospa m.invalid> wrote:
After doing a websearch, it appears that it's OK to omit the "http:" to form
a relative URL.
Of course, it's a basic part of authoring almost any site.
Are there any pitfalls to this?
You need to change links if you move a file around within a site.
For example, if there is a page
http://www.domain1.com/page1.html
with a link to
http://www.domain2.com/page2.html
you can abbreviate the second link as
//www.domain2.com/page2.html
No, you'd shorten it to just page2.html or /page2.html
The version you give is very odd and might cause problems.
What I'm wondering is if there are any drawbacks to this. (One that I can
think of is that if someone saves the HTML page to their hard disk, the link
won't work anymore since the URL is relative to the document as on the
website, not as on their harddrive.)
That's true. But the browser may alter the file when it saves it in
order to prevent this. Browsers vary, and how you trigger this
behaviour may vary as well.
Also, I just tried it and it seems that clicking on the link after the page
has been saved to the hard drive crashes IE 6.0.


Hmmm. Using the strange URL you quoted above? Not surprised that it
doesn't work, surprised that it actuallu crashes anything. But we are
talking IE here...

Steve

--
"My theories appal you, my heresies outrage you,
I never answer letters and you don't like my tie." - The Doctor

Steve Pugh <st***@pugh.net > <http://steve.pugh.net/>
Jul 20 '05 #3

"sinister" <si******@nospa m.invalid> wrote in message
news:DR******** *******@nwrddc0 1.gnilink.net.. .
After doing a websearch, it appears that it's OK to omit the "http:" to form a relative URL. Are there any pitfalls to this?

For example, if there is a page
http://www.domain1.com/page1.html
with a link to
http://www.domain2.com/page2.html
you can abbreviate the second link as
//www.domain2.com/page2.html


This isn't relative. It shows no relationship of any kind to the first page,
which is on a different, unrelated web site. It is an absolute URL without
the "http:". Maybe some browsers assume a default protocol of "http:" if you
don't use one. IE does if you leave out the protocol in the browser's
Address field; I don't know if IE will work properly if a URL like this is
in an HREF.

A relative URL is just that--identification of a page's location in
relationship to the location of the current page. If used on page1.html, a
URL of

page2.html

is a reference to a file called page2.html in the same directory as
page1.html. A reference to

../page3.html

points to a page in the first page's directory's parent directory. A
reference to

/page4.html

points to a page on the same server as the first page. These are all
relative.

Jul 20 '05 #4

"Anne van Kesteren" <ma**@annevanke steren.nl> wrote in message
news:bo******** **@reader08.wxs .nl...
sinister wrote:
After doing a websearch, it appears that it's OK to omit the "http:" to form a relative URL. Are there any pitfalls to this? It is not correct usage of the href attribute:
<http://www.w3.org/TR/REC-html40/struct/links.html#h-12.> It should
contain an URI: <http://www.w3.org/TR/REC-html40/types.html#type-uri>

Your example is _not_ a valid URI.


Which? There are 3 paths in my example.


--
Anne van Kesteren
http://www.annevankesteren.nl/

Jul 20 '05 #5

"Harlan Messinger" <h.*********@co mcast.net> wrote in message
news:bo******** *****@ID-114100.news.uni-berlin.de...

"sinister" <si******@nospa m.invalid> wrote in message
news:DR******** *******@nwrddc0 1.gnilink.net.. .
After doing a websearch, it appears that it's OK to omit the "http:" to form
a relative URL. Are there any pitfalls to this?

For example, if there is a page
http://www.domain1.com/page1.html
with a link to
http://www.domain2.com/page2.html
you can abbreviate the second link as
//www.domain2.com/page2.html


This isn't relative. It shows no relationship of any kind to the first

page, which is on a different, unrelated web site. It is an absolute URL without the "http:". Maybe some browsers assume a default protocol of "http:" if you don't use one. IE does if you leave out the protocol in the browser's
Address field; I don't know if IE will work properly if a URL like this is
in an HREF.

A relative URL is just that--identification of a page's location in
relationship to the location of the current page. If used on page1.html, a
URL of

page2.html

is a reference to a file called page2.html in the same directory as
page1.html. A reference to

../page3.html

points to a page in the first page's directory's parent directory. A
reference to

/page4.html

points to a page on the same server as the first page. These are all
relative.


But
http://www.webreference.com/html/tutorial2/3.html states:
"A relative URL that begins with // (two slashes) always replaces everything
from the hostname onwards."
It has this example: working from a base URL of
http://WebReference.com/html/
the relative URL
//www.internet.co m/
is translated into
http://www.internet.com/

Similarly, http://www.w3.org/Addressing/rfc1808.txt has a base URL of
<URL:http://a/b/c/d;p?q#f>
plus a relative URL of
//g
being mapped to
http://g
if I'm reading that doc correctly.
Jul 20 '05 #6

"Steve Pugh" <st***@pugh.net > wrote in message
news:39******** *************** *********@4ax.c om...
"sinister" <si******@nospa m.invalid> wrote:
After doing a websearch, it appears that it's OK to omit the "http:" to forma relative URL.
Of course, it's a basic part of authoring almost any site.
Are there any pitfalls to this?


You need to change links if you move a file around within a site.
For example, if there is a page
http://www.domain1.com/page1.html
with a link to
http://www.domain2.com/page2.html
you can abbreviate the second link as
//www.domain2.com/page2.html


No, you'd shorten it to just page2.html or /page2.html
The version you give is very odd and might cause problems.


I think you misunderstood my example.

If the page
http://www.domain1.com/page1.html
contains
page2.html
or
/page2.html
those relative URLs become
http://www.domain1.com/page1.html
whereas I want "domain2.co m", not "domain1.co m".

About the strange example, with the leading "//":
http://www.webreference.com/html/tutorial2/3.html states:
"A relative URL that begins with // (two slashes) always replaces everything
from the hostname onwards."
It has this example: working from a base URL of
http://WebReference.com/html/
the relative URL
//www.internet.co m/
is translated into
http://www.internet.com/

Similarly, http://www.w3.org/Addressing/rfc1808.txt has a base URL of
<URL:http://a/b/c/d;p?q#f>
plus a relative URL of
//g
being mapped to
http://g
if I'm reading that doc correctly.
What I'm wondering is if there are any drawbacks to this. (One that I canthink of is that if someone saves the HTML page to their hard disk, the linkwon't work anymore since the URL is relative to the document as on the
website, not as on their harddrive.)


That's true. But the browser may alter the file when it saves it in
order to prevent this. Browsers vary, and how you trigger this
behaviour may vary as well.


Right.
Also, I just tried it and it seems that clicking on the link after the pagehas been saved to the hard drive crashes IE 6.0.


Hmmm. Using the strange URL you quoted above? Not surprised that it
doesn't work, surprised that it actuallu crashes anything. But we are
talking IE here...


Right...
Steve

--
"My theories appal you, my heresies outrage you,
I never answer letters and you don't like my tie." - The Doctor

Steve Pugh <st***@pugh.net > <http://steve.pugh.net/>



Jul 20 '05 #7
Anne van Kesteren wrote:
sinister wrote:
After doing a websearch, it appears that it's OK to omit the "http:" to form
a relative URL. Are there any pitfalls to this?


It is not correct usage of the href attribute:
<http://www.w3.org/TR/REC-html40/struct/links.html#h-12.> It should
contain an URI: <http://www.w3.org/TR/REC-html40/types.html#type-uri>

Your example is _not_ a valid URI.


My understanding of RFC2396 is that //host and //host/path are
relative URIs, called network-path references (sec. 5). Appendix
C.1, titled "Normal Examples", shows how the relative URI //g
should be resolved when the base URI is http://a/b/c/d;p?q . The
resulting absolute URI is http://g . And that's not even an
abnormal example.

The HTML4.01 specification, section 6.4, says: "Relative URIs are
resolved to full URIs using a base URI. [RFC1808], section 3,
defines the normative algorithm for this process". But section 3
doesn't define any process of resolving relative URIs; section 3
talks about the various ways of establishing a base URL. And
indeed, HTML4.01, sec. 12.4.1, says that "user agents must
calculate the base URI for resolving relative URIs according to
[RFC1808], section 3". Does that mean there isn't a normative
algorithm for resolving URIs?

RFC1808, sec. 4, and RFC2396, sec. 5.2, on the other hand, suggest
possible algorithms for resolving relative URLs.

--
Jock
Jul 20 '05 #8
"sinister" <si******@nospa m.invalid> wrote:
"Steve Pugh" <st***@pugh.net > wrote:
"sinister" <si******@nospa m.invalid> wrote:
>After doing a websearch, it appears that it's OK to omit the "http:" to
>form a relative URL.

>For example, if there is a page
>http://www.domain1.com/page1.html
>with a link to
>http://www.domain2.com/page2.html
>you can abbreviate the second link as
>//www.domain2.com/page2.html


No, you'd shorten it to just page2.html or /page2.html
The version you give is very odd and might cause problems.


I think you misunderstood my example.


Sorry, I missed the fact that they are two different domains.

And on reflection, once my memory started working I realised that yes,
a URL starting with // will resolve as //hostname/path and that should
work in any decent browser.

Calling it a relative URL is a bit misleading. Strictly speaking it is
a relative URL, but really the only thing it's relative to is the
protocol.

Which explains your problem with locally saved copies.
//example.com/foo/bar is then resolved as being
file://example.com/foo/bar and the browser goes off looking for a
local host called example.com.
Obviously it won't find it, but IE still shouldn't have crashed.

Steve

--
"My theories appal you, my heresies outrage you,
I never answer letters and you don't like my tie." - The Doctor

Steve Pugh <st***@pugh.net > <http://steve.pugh.net/>
Jul 20 '05 #9
On Wed, 5 Nov 2003, Steve Pugh wrote:
a URL starting with // will resolve as //hostname/path and that should
work in any decent browser.


Do you have an interworking specification that says it SHOULD, or
is that merely your opinion?
Jul 20 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
5792
by: ryan.fairchild | last post by:
Ok I basically am creating a container for a bunch of other <div> tags. But I want to make four jpegs/gif/whatever that goes in each corner so they look rounded. I thought this is how I would do it but I could be wrong. body { background:#999 url("http://") no-repeat top left; background/* */:/**/url("http://") no-repeat top right;...
31
4824
by: Yeah | last post by:
Is it absolutely necessary to include "http://" in an A HREF hyperlink? Would it be wise to remove this from one's Links page, just to save code?
0
7736
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8066
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8249
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
6461
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5305
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3743
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2251
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1350
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1066
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.