View Full Version : How do I use a variable to change site location easily?
DOSrelic
01-26-2007, 07:54 PM
My ISP has an unusual setup in that I cannot seem to be able to use relative URLs Therefore I would like to use a variable in my HTML code that I can assign the site's location to. EG: I have just changed ISPs to go on broadband and realised all my pages used literal URLs so I am having to parse all the relevant files and change "dosrelic.kol.co.nz" to homepages.slingshot.co.nz/~dosrelic (http://homepages.slingshot.co.nz/~dosrelic/)!
This would be so much easier and quicker if I had a variable in an include file that I could change. :smack: How can I do that in HTML please?
Please visit my new homepage [Link removed, it's already posted above] where I still need to alter my shifted old site to avoid ther 404 errors! Any suggestions and or guidance would be GREATFULLY appreciated, :p cheers in advance. lol :hellother
Oh BTW where do you edit my signature please?
Thank you & Best Regards
¨`·._.®._.·´¨
Martin Richka [DOSrelic]
Spock
01-27-2007, 08:06 AM
I have edited your post to make it a bit more readable and removed all duplicate links. We have had a lot of Spammers recently who like to post link farms and more than one link in a post is considered a link farm.
All signatures have been turned off for new users and will only be allowed once you have contributed enough to warrant our trust as Spammers also use signatures to advertise their sites.
Unfortunately, I'm not conversant enough with HTML to be able to adequately answer your question, so will leave that to one of our resident professionals.
DOSrelic
01-30-2007, 01:33 PM
Hi Spock, were you aware that I have been a member for some time now?
This was an earlier question of mine. (when i had a signature!) lol http://developers.evrsoft.com/forum/showthread.php?p=20474
I hope one of the sages will know the answer, thanks.
Spock
01-30-2007, 02:47 PM
Hi Spock, were you aware that I have been a member for some time now? ...
Yes, as it shows in your user information on the left of the post. You joined Apr 2005.
My post was simply meant as a continued point of information for all members, I never meant to insinuate that you might be a Spammer. If you have been a trusted member for some time and you have a valid reason to have multiple links in your post, it probably won't be modified ... as long as the links don't all point to the same website.
I also hope one of our sages is able to answer your question, after all, that's why I left it in place. ;)
PsychoticDude85
01-30-2007, 05:45 PM
Something like the <base> tag if I understand your question?
http://www.w3schools.com/tags/tag_base.asp
DOSrelic
01-30-2007, 08:00 PM
PsychoticDude85 you've done it again I think, THANK YOU! I will investigate that further, although their hompage server doesn't seem to like relative links done by hand manually so far. :( Long time no hear as I've lost all me hotmail contacts when upgrading to XP. Cheers again mate. lol
®
Spock
01-31-2007, 03:04 PM
... relative URLs ...
I just realized what you are asking and may have an answer you can live with and use as I use it on my website. I run changes on my local system to ensure there are no mistakes and then upload it to the host where it runs with no problems, so this may be of use to you.
Consider the following folder layout:
Home
|
|-- images
|
|-- pages
If your index.html is located in your home folder, as it should be, but you want to keep everything compartmentalized so you can find what you are looking for you will keep most of your website in sub-folders based on what the pages are for.
In the above structure, I have set up a simple arrangement where all pages of the website except the main index.html are stored in a folder called pages. All images used by the website are stored in the images folder. How to make them work on your local system and on the remote host at the same time without having to place a complete URL in every reference?
Use relative addressing.
If you have a page in the pages folder called about.htm, you could use the following code in your index .html to reference it:
<a class="img" href="./pages/about.htm" title="About Us"> <border="0" alt="banner" title="About Us"> <B>About Us</B></a>
notice the "./" in front of the folder name? the single dot indicates you are starting with the current folder. You could easily leave it out but I like to add it for completeness.
Let's say there is a picture in the images folder that you want to display in the about.htm file, how would that link look? You could use something like the following to display it:
<img src="../images/banner.gif" width="232" height="63" border="0" alt="Our Company" title="About us information Page of Our Company">
Notice that the folder name is preceded by two dots and a slash this time. This indicates you are moving up the folder tree one level. So from the pages folder the reference moves up to Home and then down to the images folder to finally find the image you wish to display.
If you have to move up two levels, simple put "../../" in front of your folder name.
Hope this helps some and sorry I didn't realize what you were asking for. BTW, the "./" and "../" references have been with us since the old DOS days of the IBM PC and M$ DOS. ;)
PsychoticDude85
02-01-2007, 08:11 AM
Didn't the first post say he couldn't use relative urls? Though admittedly base might not work also if that is the case.
Spock
02-01-2007, 11:32 AM
Didn't the first post say he couldn't use relative urls? Though admittedly base might not work also if that is the case.
Since I have no idea what or how he tried to implement his links, I thought it couldn't hurt to jump in. If he has already tried my suggestion, then it was only a wasted post. ;)
PsychoticDude85
02-01-2007, 02:00 PM
We will find out in due time I suppose. <base> is a good extension of what you described anyway, it would mean having something like (using your directory structure from before):
<base href="http://site.com/">
And then, you wouldn't need to use ./ and ../. Because even when in the pages/ directory you can access the images with src="images/file.jpg" because it becomes in effect an absolute reference to http://site.com/images/file.jpg regardless of where the code is placed.
DOSrelic
02-01-2007, 05:14 PM
Well guys never a wasted post Spock but i think it may be my own ineptitude that makes me think it won't do relatives. Perhaps i should look at my coding more closely before bothering you knowledgeable chapsQ :) BTW: thanks gain. lol
Spock
02-01-2007, 06:06 PM
... it may be my own ineptitude that makes me think it won't do relatives. ...
We all had to start someplace and this is a good place to get help. Please post back and let us know what you did and how it worked for you. :)
Gosh, he called me knowledgeable! :shy: Boy do I have him fooled. :hehe:
vBulletin® v3.8.6, Copyright ©2000-2012, Jelsoft Enterprises Ltd.