/    Sign up×
Community /Pin to ProfileBookmark

more on relative vs absolute paths

Maybe this is not a problem with other HTML editors, , if not please let me know, as I’m still using the old HOMESITE editor.

I like to use relative paths, mainly so I can test my site locally with browsers on my file system, and also because absolute paths to graphics has in one instance caused my hosting company a lot of grief (I’ll skip the details unless someone is interested).

So when I’m developing, it would really be nice if I could still use the “root” (/) as a starting point. That way, for example,, wherever a page ends up in a directory tree, a <link> tag like this will always work…

<link rel=”stylesheet” type = “text/css” href=”/styles/myStyles.css” >

But of course that won’t work when testing on my home computer. Is there a workaround for this? Is there a way to tell Homesite that when interpreting links, “/” should refer to the project root? If not, would Coffeecup be able to do this? I don’t think I can use “./” as a substitute, can I?

to post a comment
Full-stack Developer

16 Comments(s)

Copy linkTweet thisAlerts:
@Kevin2Jan 09.2014 — You can use ../

For example, if your referring page is at /stuff/morestuff/index.htm you would use
[CODE]<link rel="stylesheet" type = "text/css" href="../../styles/myStyles.css" >[/CODE]
Copy linkTweet thisAlerts:
@PeterPan_321authorJan 09.2014 — Yeah thanks. I do that a lot, and in fact the editor usually does that for me pretty well. But of course being able to start from the project root would be ideal. If there's no other way, i can live with it.
Copy linkTweet thisAlerts:
@Kevin2Jan 09.2014 — Unless you put your local files at the root of the drive that's your only choice. I've thought about using a thumbdrive for website development simply because of that. But it means keeping track of that drive, making sure it's plugged in when I need to work on a site, etc. etc. So far, not worth the effort. Although it might be worth the effort to have local website files on a dedicated partition.
Copy linkTweet thisAlerts:
@PeterPan_321authorJan 09.2014 — Kevin: Yeah that's a really good idea!!! I never thought of that! I don't know if I'd want to use a thumb drive either, but either a small partition on my main drive or a secondary drive would solve this issue for good!

Thanks!!!
Copy linkTweet thisAlerts:
@rootJan 10.2014 — / = root

./ = current working path where html document is saved

../ = move up one directory

Using relative paths should not pose a problem in any editor, the only editor that I found was a royal pain in the rear was the Adobe Indepth which insisted on writing in javascript and fixing paths so it was an absolute path.

Your testing server... What are you using?
Copy linkTweet thisAlerts:
@PeterPan_321authorJan 10.2014 — Mr :127.0.0.1 (can i call you loopback for short ;-) By hosting server has no problem with any of those constructs. Its just that when testing code in my own machine, any link that starts with a root "/" will try to go to the root of my "C:" drive, instead of the root of my project. This is all static page development, so there really is no server involved... just a browser.
Copy linkTweet thisAlerts:
@rootJan 10.2014 — That is why I asked if you have a server on your PC for proper testing. If not then I can suggest that you try something like XAMPP which you can get from portable Apps which is a system that allows you to install and run from a *USB drive / flash drive / thumb drive / stick drive and test in a proper web based environment that you can refer to in a web browser by IP address or the loopback name.

If you edit your local hosts file, you can add in a name and point it to 127.0.0.1 and end up with http://testing/ for example

your hosts file is found in [I]%windir%system32driversetchosts[/I]

copy [B]%windir%system32driversetchosts[/B] and open a [B][I]run[/I][/B] dialog and paste, hit return and select [I]notepad[/I] to open the file then you will see something like... [CODE]# Copyright (c) 1993-1999 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
# 102.54.94.97 rhino.acme.com # source server
# 38.25.63.10 x.acme.com # x client host

127.0.0.1 localhost
[/CODE]


after 127.0.0.1 localhost on a new line put

127.0.0.1 testing

then save the file, close and then you will have a URL for http://testing/ that will open up the root page for your installed server (obviously when you have your server installed!)

So... go here http://portableapps.com/ and grab the installer for the portable apps program and then go here http://portableapps.com/apps/development/xampp and grab XAMPP, install and then run, the server will then respond to http://testing/ when you request it in a web browser.







  • * delete as required
  • Copy linkTweet thisAlerts:
    @jedaisoulJan 10.2014 — One way to have project-specific root directories is to install multiple instances of a localhost. I use wampserver installed on a network file server, and separately on the local workstation, but you could have multiple instances on your workstation. Each instance points the localhost root (http://127.0.0.1 otherwise known as http://localhost) to the www directory in ...wamp directory you installed wamp into. So you can have, say, C:project1wampwww... and C:project2wampwww... etc... So, depending upon which instance you have running, localhost will point to a different root. However, I'm no sure what would happen if you tried running multiple instances simultaneously on a single workstation.

    If you need to work on multiple projects simultaneously, you would need to have multiple servers on your LAN, with one localhost on each. That is not as expensive as it may sound, I use a spare 10 inch netbook computer as a network file server. Throughput and disk capacity is not an issue.
    Copy linkTweet thisAlerts:
    @Gray1989Jan 10.2014 — If you don't want to install a server and don't want to use a flashdrive, you can use the "subst" command in Windows to associate a new virtual drive to an existing path on the local machine. Open a command prompt and type the following to create a new X: drive for the path C:WebFiles

    [CODE]subst X: C:WebFiles[/CODE]

    If you ever need to delete the virtual drive, type the following:

    [CODE]subst /D X:[/CODE]
    Copy linkTweet thisAlerts:
    @jedaisoulJan 10.2014 — If you don't want to install a server and don't want to use a flashdrive, you can use the "subst" command in Windows to associate a new virtual drive to an existing path on the local machine.[/QUOTE]

    That takes me back. I did not know that old MSDOS command still works! If so, it is a far simpler solution.
    Copy linkTweet thisAlerts:
    @Gray1989Jan 10.2014 — Yeah I instantly thought of it when I read this thread. Only one setback I can think of is it might not persist across reboots. Then again it's pretty easy to make a batch file to run the command so it won't need to be typed each time. Could even place a shortcut to it in the start menu's startup folder so it's automatically done at each login (if of course the command prompt flashing by on login isn't considered an annoyance).
    Copy linkTweet thisAlerts:
    @rootJan 10.2014 — That takes me back. I did not know that old MSDOS command still works! If so, it is a far simpler solution.[/QUOTE]

    Not really because your links will end up with a directory structure referencing files:X:blahblahwebpage.html where as installing XAMPP is as simple as a double click on an Icon, your testing will be exactly the same as it would be on a web host but all your debugging will be local.

    Really don't see how putting a development service on your PC is going to be a hard job.
    Copy linkTweet thisAlerts:
    @PeterPan_321authorJan 10.2014 — Well thanks everyone. I must say this webdeveloper forum is filled with some of the most helpful folks I've encountered in quite some time. Very refreshing. As is often the case, in the midst of many things to do I also have many new things to try. But that sure beats not having a clue with no one to help.

    As far as the web server, I guess I'm going to have to do this eventually, especially if I begin experimenting with a CMS system like Joomla. I do have my concerns though. First, I think it best i install a web server on another box. I certainly have extras floating around. That way I can better duplicate the operating environment of my hosting company. I am curious about the virtual drive solution too, and adding a name to my local hosts is an idea something I totally forgot! Lots of good tips. Thanks again everyone!
    Copy linkTweet thisAlerts:
    @Gray1989Jan 10.2014 — Not really because your links will end up with a directory structure referencing files:X:blahblahwebpage.html where as installing XAMPP is as simple as a double click on an Icon, your testing will be exactly the same as it would be on a web host but all your debugging will be local.

    Really don't see how putting a development service on your PC is going to be a hard job.[/QUOTE]


    I'd have to agree with you, and I would also recommend XAMPP as the software of choice. There is the right way of doing things, and the quick way of doing things. However sometimes the quick way doesn't hurt.
    Copy linkTweet thisAlerts:
    @Gray1989Jan 10.2014 — Thanks again everyone![/QUOTE]

    No problem at all ?
    Copy linkTweet thisAlerts:
    @John_marksJan 31.2014 — Thanks for sharing nice information,with us I strongly believe it is helpful for me as well as my forum friends.
    ×

    Success!

    Help @PeterPan_321 spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 5.15,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @AriseFacilitySolutions09,
    tipped: article
    amount: 1000 SATS,

    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,
    )...