Setting a base url Path using the BASE Tag
We thought to keep this tidbit about urls until now so you have a bit more practice and understanding of how file paths and server paths work. The base tag enables you to change the base path of a domain in other words if one is not defined in a link we can automatically set a default base path and a default target option. Join this video as we explore how this works in our last video of this session.
Video Transcript
00:00Time for us to take a small detour
00:02and talk about URLs or links
00:05you already created links. remember?
00:10So I created two links, two sample links that don't work
00:14they are broken.
00:15How sad.
00:15If i click on the basics link it will go to a link that just doesn't exist.
00:19The rezone is that I'm using a relative path
00:22Now if we go into our editor, to look at the code itself
00:26We will see that the link is going to the page /catagory/developer-basics
00:31But because we are working locally on our computer
00:33This just doesn't exist.
00:35Now if we wanted it to go to the right page.
00:38We would need to type the full qualified path.
00:40which would be http://....
00:46If we would do that and go back into the browser refresh it would
00:51take us to the right path, because we are using an absolute path.
00:56There is a difference between absolute and relative paths
01:00In our case, we really want to keep our URLs relative
01:03do you by any chance know why would I want to have relative paths?
01:07Why would it be a good idea to have relative paths?
01:15Mom: so you have control on the specific place your going...
01:20Ben: you would have control if you used absolute paths as well...
01:25But... what could i do ... let me give you a scenario
01:30You are married to someone that is called Simon
01:35And he lives in Jerusalem
01:38Now if I asked you to call your husband , would you call for Simon from Jerusalem
01:42because it's bothering our recording
01:45or would you say "I know who your talking about".
01:48now what would happen if you move an apartment
01:51Now you moved back to New York
01:52And your sitting in new york
01:54And i come to you again and
01:55I tell you: could you tell Simon from Jerusalem to stop making noise
01:59Well he moved with you because your married
02:02But i'm still calling him Simon from Jerusalem
02:06Because i connected him to that specific location.
02:09That was an absolute path.
02:13Contrary to that when I use a relative path
02:18I'm saying , call Simon from where ever you are.
02:22Right now your in this house So in this house go to "catagory..."
02:29and get that information for me.
02:31By the way these rules work the same with images as well.
02:34Exact same way.
02:36When you set the images path it's the exact same logic.
02:40this won't work if you are in New York now and Simon is not in New York
02:46It adds some extra work on your part when developing when working with these details
02:54But on the other hand, when you want to move for example
02:57our site to a new domain
02:58and we changed our brand all we had to do is move because
03:03we didn't have absolute paths in our code
03:09We didn't need to go into every single place there is a link and update it.
03:14We never set explicitly, we always used relative paths.
03:18So that's the most important thing about relative paths
03:24With it if you download a page from a site but you don't download the full site
03:30There is a way around it, a way to solve it
03:32you can for one fix this for your site in general
03:36Maybe all the links on your site are ment to go to 02GEEK.com
03:42Such as in our case
03:42We can tell the browser that all relative paths should
03:47Use a base path
03:51We do that using the BASE tag in the HEAD
03:54We tell it that our base href path is going to be 02geek.com
03:59It could of have been any path
04:04In this case, this is good enough.
04:14We know our base path is 02geek.com
04:16by defining the base path and we go into our browser
04:23Click on refresh and this time around all the links will work again.
04:32Even though we didn't define it link by link
04:37Any time i don't have an absolute path it would use the path in the base path.
04:42If i ever go inside and change the link and put a link to for example cnn.com
04:49I'll wrap the copy CNN and convert it into a link
04:59and I'll send them to the full link
05:06With the full http://...
05:10If i do that this way and we go into our browser
05:12and search for the new CNN link
05:15When we click on it, it will take us to the CNN site
05:18It's not going to go into 02geek.com/cnn.com
05:21Even though our base path is set to go to 02geek.com
05:25Because by defining the full link we defined a new base path for that link.
05:28On contrary, if we ommited the 'http' and just typed 'cnn.com'
05:31it won't work. It would treat it as a relative path.
05:39The browser doesn't know we meant the fully qualified site called cnn.com
05:43The only way for the browser to recognize it is if we fully declare the site starting with http...
05:49A path always starts with HTTP or HTTPS
05:53So that's our base URL
05:57There is one more thing you can do with the base URL
05:59You can define a target as well
06:01If you remember from our talks about the HREF
06:04We can open the link in a new window by defining a target
06:08If you don't remember it please go back to the lectures on links
06:14You can change the default target by defining it in the BASE tag
06:21If this video was a bit hard for you like it was for you mom
06:33I strongly encourage you to go back now to the href again
06:37go back to the images again
06:38What we learned here will effect and shed light on your understanding their as well
06:46It's really important that you get these concepts
06:52I'll go back to my browser and click back
06:57This time around no mater what page I click on
07:01It will open up in a new tab
07:03The default now is to open in a new tab
07:07How do I undo that?
07:10If I wanted a specific link to open up in the same window
07:12How can I make it open up in the same window?
07:14I would then go directly to the link and override the target.
07:18For example here. I would add a target and set it to _self.
07:28By setting the target to _self when I click it, it will open in itself.
07:49Mom: wow
07:51We learned a lot. if its hard go back to the earlier videos (and ask questions that's what we are here for)
08:01If it was easy then hope along to the next video.
08:03Practice
08:06It's only simple after you practice
08:07Until you do it - it's theory.
08:13Theory is always harder then practice
08:15If i sent you off for some homework
08:19I would say work with relative paths
08:20put images in relative paths
08:21load the images from different servers
08:25load them internally
08:26different folders and so on...
08:27That's the biggest practice you can do
08:29Mom: Life is funny
08:33I used to tell you as a boy - do your lessons now your telling me to do mine ;)
