Web Hosting Forum | Lunarpages

Author Topic: Need Help with Subdomains and Relative Paths  (Read 9932 times)

Offline Mike McCollister

  • Space Explorer
  • ***
  • Posts: 9
Need Help with Subdomains and Relative Paths
« on: September 23, 2013, 11:49:06 AM »
I am toying with subdomains on my site. However, I am having some difficulty with some relative paths for my JavaScript and CSS files. For example in my http://MyDomain.com/brother/index.htm file, I have the following:

<link href="../style.css" rel="stylesheet" type="text/css" />
<script src="../scripts.js" type="text/javascript"></script>

This works fine unless I setup my “brother” subdomain point to the domain root of /public_html/brother. Once I try http://brother.MyDomain.com I get the proper HTML page but it can’t find style.css and scripts.js. I realize that I can put in absolute addresses for these files as such:

<link href="http://MyDomain.com/style.css" rel="stylesheet" type="text/css" />
<script src=" http:///MyDomain.com/scripts.js" type="text/javascript"></script>

But that will make developing this site difficult on my local machine.

Are there any techniques that I can use to keep the relative paths?

I searched around some and see that there may be a technique to add in the .htaccess to let the server know where to find
said files. Does anyone have any idea on how to do that?

Thanks,

Mike

Offline MrPhil

  • Senior Moderator
  • Berserker Poster
  • *****
  • Posts: 6197
Re: Need Help with Subdomains and Relative Paths
« Reply #1 on: September 23, 2013, 01:16:24 PM »
Well, the directory tree for the subdomain (from root / ) is completely independent of the primary domain's directory tree (from root / ). You can't get to files in the primary domain from the subdomain. Maybe in the other direction, as /brother/..., but not from subdomain to primary, as it has no idea what the primary's tree structure is.

Why do they have to be relative? Even within one site (primary or subdomain), that can trip you up when you move things around. Assuming you're using PHP or some other scripting language, how about defining some constant "home address" such as "http://MyDomain.com/" that you simply glue on to the front of any desired file, e.g., "style.css" or "scripts.js".
Visit My Site

E-mail Me
  
-= From the ashes shall rise a sooty tern =-

Offline Mike McCollister

  • Space Explorer
  • ***
  • Posts: 9
Re: Need Help with Subdomains and Relative Paths
« Reply #2 on: September 23, 2013, 02:57:45 PM »
Mr Phil,

Thanks for the suggestion. I'm not using PHP or any server side scripting so having a "home directory" constant won't work. I'll look some more with the .htaccess stuff online.

Thanks,

Mike

Offline MrPhil

  • Senior Moderator
  • Berserker Poster
  • *****
  • Posts: 6197
Re: Need Help with Subdomains and Relative Paths
« Reply #3 on: September 23, 2013, 05:19:43 PM »
No scripting at all? Writing raw HTML is the hard way of doing it, but it's up to you. Even a simple macro processor like cpp or m4 might relieve you of a lot of the burden. Of course, you would run your markup through a processor to get the static .html file, which would then go onto the site.

A <base> tag might prove useful for telling the browser what the "home directory" is for all relative addresses. You mentioned .htaccess -- did you have something in mind?
Visit My Site

E-mail Me
  
-= From the ashes shall rise a sooty tern =-

Offline Nepster Martin

  • Website Clone | Website Clone Script
  • Intergalactic Cowboy
  • *****
  • Posts: 68
    • NCrypted Technologies
Re: Need Help with Subdomains and Relative Paths
« Reply #4 on: October 17, 2013, 10:26:36 PM »
I think you can follow developing your website using first in local and than upload to live. Setup WordPress or any other CMS on your local machine and implementIt w your website there locally and than upload your website. It will help you in implementing your sub-domain also.

 

Share |