HTML HTML Basics Going Further with HTML Root-relative Paths

dala lin
dala lin
Front End Web Development Techdegree Student 390 Points

How to change root-relative path back to file path for my website on terminal

So i followed the instruction on Teacher's note and it works! But, how to I change it back to develop my website on my local hard drive instead of through web server?

1 Answer

Matthew Underhill
Matthew Underhill
18,313 Points

You have to change them all back to absolute paths manually as your computer does not see the root of your web directory as the actual root of your project.

The easiest way to avoid swapping them back is to use a web server MAMP/WAMP as you can set the project path in there so your computer then acts like a web server.

Once you start learning languages such as PHP, you will see how this can become much easier, because you can for example store your root paths as constants in one file and then require that file in every web page you make. That way if any directory/file is moved, you only have to change the constants once, all and all your sites links will be updated.

e.g in PHP

define("BASE_URL","/");
define("ROOT_PATH",$_SERVER["DOCUMENT_ROOT"] . "/");

Matt