A relative URL is any URL that doesn’t explicitly specify the protocol (e.g., ” http:// ” or ” https:// “) and/or domain ( www.example.com ), which forces the visitor’s web browser (or the search engine bots) to assume it refers to the same site on which the URL appears.
Relative Link
A relative link, on the other hand, takes advantage of the fact that the server knows where the current document is. Thus, if we want to link to another document in the same directory, we don’t need to write out the full URL. All we need to use is the name of the file.
Relative Path vs Absolute Path:
Absolute paths contain a complete URL, which includes a protocol, the website’s domain name, and possibly a specific file, subfolder, or page name. For example A Folder
The URL here, http://domain.com/ourfolder, can be entered into a browser’s search bar, and we’ll be taken where we want to go. While our personal browser may let us omit the protocol, https://, we should always include the protocol when coding absolute links to make sure they work for all visitors.
Conversely, a relative link only includes the name of a specific file or page, which is relative, to the current path. If we keep all of our website’s files in a single directory, we can establish links between pages as follows:
The Homepage of my website
Relative URLs come in three flavors:
1. Path-Relative URLs
<a href=”services/video-production/corporate-videos”>
<a href=”corporate-videos”>
The URL begins with the name of a page, or the name of a path (folder, directory, whatever) containing a page. Browsers assume this link refers to a page that is either in the same directory as the page on which the link appears, or in a subdirectory below it.
For example, let’s say a site has a Services section, and under that have a subsection called Video Production, and that the overview page for this service has the URL:
http://example.com/services/video-production
<a href=”video-production”>
Having no domain or foreslashes, this link is assumed by browsers to be relative to the path of the page on which it appears, correctly calculating the absolute URL for this link as:
“http://example.com/services/video-production/”
This is a perfectly valid use for path-relative URLs.
2. Root-Relative URLs
Examples:
<a href=”/services/”>
<a href=”/services/video-production”>
The leading foreslash before “services” indicates that this URL is relative to the root of the site’s URL structure, rather than the path of the page on which it appears. In this case, the absolute URL is calculated to be:
“http://example.com”
+ “/services/video-production“
Root-relative URLs are probably the safest kind of relative URL overall, both for minimizing the potential for human error, and for simplifying site maintenance. When absolute URLs aren’t an option, root-relative URLs are probably best.
3. Protocol-Relative URLs
Examples:
<a href=”//services/”>
<a href=”//services/video-production”>
The double-leading-foreslash (“//”) tells the browser to use the same connection scheme or protocol (i.e., either HTTP or HTTPS) as used to request the page on which the URL appears, so if this URL is on a page whose URL begins “https://”, then protocol-relative URLs on that page should also begin with “https://”.
Screenshot before applying snippets of code:
Screenshot after applying snippets of code:
Good post. I learn something totally new and challenging on sites I stumbleupon every day.
Great article post. Really looking forward to read more. Want more.
You’ve got superb info in this case.
Thank you for every other informative blog.
Major thanks for the article. Thanks Again. Keep writing.
Appreciate you sharing, great blog post. Fantastic.
Great article! We are linking to this great article on our site. Keep up the good writing.
My brother recommended I would possibly like this website.
Thanks for discussing the issues and covering them in a well written format.
Way cool! Some very valid points! I appreciate you writing this post and the rest of the site is also very good.
I am actually pleased to read this web site posts which includes tons of valuable facts, thanks for providing such information.
Thank you for every other informative blog.
I am actually glad to read this website posts which carries plenty of useful information, thanks for providing these kinds of data.
Valuable information. Lucky me I found your website by accident, and I am shocked why this accident didn’t happened earlier! I bookmarked it.
Thanks in favor of sharing such a pleasant opinion, piece.
You made some good points there. I checked on the web for more information about the issue .
Greetings! Very useful advice in this particular article! It is the little changes that make the biggest changes. Many thanks for sharing!
Great blog!
Appreciate it! Quite a lot of knowledge.
Absolutely pent subject matter, Really enjoyed looking through.
thanks great site
thanks.
I appreciate your piece of work, regards for all the great blog posts.
I like this web blog very much, Its a really nice position to read and incur information.
You made a number of fine points there. I did a search on the topic and found the majority of persons will have the same opinion with your blog.
your site is very nice, but you need to pay more attention to the comments of the users.
Spot on with this write-up, I truly think this website needs much more consideration. I all probably be again to read much more, thanks for that info. Bryant Kisamore
You made some good points there. I looked on the internet for the issue and found most guys will go along with with your blog. Heriberto Heep
Just wanna tell that this is very beneficial , Thanks for taking your time to write this. Marshall Guler
Appreciate you sharing, great blog post. Much thanks again. Much obliged. Sid Sabates
Everything is categorically way in taking into consideration a unquestionably certain tally of the challenges. It was agreed informative. Your website is certainly helpful. Many thanks for sharing!
Hi there, just became alert tօ your blog through Google,
and found that it is really informative. I am gߋnna watch out for brussels.
I’ll aрpreciatе if you cоntinue this in future.
Many people will bе benefited from your writing. Cһeers!
I have been exploring for a little for any high quality articles or blog posts on this kind of area . Exploring in Yahoo I at last stumbled upon this web site. Reading this info So i am happy to convey that I have a very good uncanny feeling I discovered exactly what I needed. I most certainly will make sure to don?t forget this site and give it a look regularly.
This design is spectacular! You definitely know how to keep a reader amused.
I was almost moved to start my own blog (well, almost…HaHa!) Great job.
I really loved what you had to say, and more than that, how you presented it.
Too cool!
Thank you for writing the article. I like the topic too.
Thanks for posting such an excellent article. It helped me a lot and I love the subject matter.
Thank you for your post. I liked reading it because it addressed my issue. It helped me a lot and I hope it will help others too.
Thanks for your help and for posting this. It’s been wonderful.
Thank you for writing such a great article. It helped me a lot and I love the subject.
First off I would like to say superb blog!
May I request more information on the subject? All of your articles are extremely useful to me. Thank you!
yes sure you can contact me on skype : suren.sharma41 or on mail : smartwebperfection@gmail.com
You’ve been very helpful to me. Thank you!
Hi my friend! I want to say that this post is amazing, nice written and include almost all significant infos. I would like to see more posts like this.
Great blog here!
If some one needs expert view about blogging then i suggest him/her to pay a quick visit this blog, Keep up the nice job.
Very nice post. I just stumbled upon your weblog and wished to say that I have really enjoyed surfing around your blog posts. After all I’ll be subscribing to your feed and I hope you write again very soon!
I want to thank you for your assistance and this post. It’s been great.
Thank you for providing me with these article examples.
Hello there, simply become alert to your weblog via Google, and found that it is really informative. I will be grateful if you continue this in future. A lot of folks will be benefited out of your writing. Cheers!
you’ve got a fantastic blog here!
Dude these articles have been really helpful to me. They really helped me out.
You made some respectable points there. I regarded on the internet for the problem and found most people will go together with together with your website.
Thank you for writing about this topic. Your post really helped me and I hope it can help others too.
Thank you for your excellent articles.
Great web site. A lot of helpful info here. And certainly, thank you to your effort!
Youre so cool! I dont suppose Ive read anything like this before. So nice to seek out someone with some unique thoughts on this subject. Really thank you for starting this up. this web site is one thing that’s needed on the net, someone with somewhat originality. Useful job for bringing something new to the web!
Wow, wonderful blog layout! How long have you been blogging for ? you make blogging look easy. The overall look of your website is great, let alone the content!
Thanks for your thoughts.