Absolute vs. relative URLs in navigation bar links

R

Randy Morgan

I'm probably going to use a navigation menu from www.dynamicdrive.com
that requires a fair bit of customization. I have to manually enter the
links for all the menu items, and it got me thinking about using
absolute URLs vs. relative URLs (my nomenclature may be off but I hope
the meaning is clear). Right now I'm using a custom linkbar, so FP
manages everything when pages get moved around or new pages get added,
and it uses relative URLs, but the script I'm considering won't be that
"smart".

Are there any inherent advantages or disadvantages of one approach vs.
the other? It seems simpler, although a bit more typing is involved, to
use absolute URLs, but I'm wondering how that might affect pageloads and
the way stat packages would interpet things.

Any opinions?

Thanks,
 
P

p c

For all links on your site, you may want to use relative links fro the
following reasons:

1. If you decide to move your web sit to a different web server, you
change the domain name (e.g. www.myfirstdomain.com to
www.anotherdomain.com) or you want to re-use the pages/code at another
site, all relative links will work as-is without change.

2. If you use FPSE for your site and you move or re-name the page using
FP, FP will adjust all relative links to point to the correct page. It
does not do it for absolute links.

3. If you edit pages in local folder (not same as an FP local web),
relative links wail work. This way you can test develop and test your
pages locally. This the method used by most web developers who use ftp
too upload to sites or to upload to sites that do not support FPSE. In
this case, FP is just another HTML editor.

...PC
 
R

Randy Morgan

Thanks for the inputs. Your comment number 3 below brings to part of my
problem, and while I'm not even sure if I can explain it right I'm going
to try. Please forgive any lapses in proper web syntax...

I am trying to test a new menu script on my local test machine, which
sites on my home network. It's not running IIS (can't bring myself to
spend $200 upgrade to XP Pro a WinXP Home machine that I just paid $100
to upgrade from WinME less than a year ago), so none of the ASP stuff
will work, but it is running Apache/PHP and most of it works well enough
for me to do at least some testing. The menu is all JavaScript/DHTML so
I'm fine.

Anyway, there are some .js files that need to be called from every page
that has a menu. For all the pages in the root of my web, all is well,
but for those pages that live one level down the relative URLs break.

I publish the actual site to www.mysite.com. The way the directory
structure works on the test machine on my home network (I installed
xampp), you publish (copy, actually) the web to an htdocs directory and
then browse to it at http://ip_address/mysite/. A page in the root
directory would be browsed at http://ip_address/mysite/page.htm.

Since the .js files must be called to each page, and since I absolutely
do not want to try to make different .js files depending on where in the
directory structure a page lives, I'm trying to use relative URLs to
point to the scripts and to the images that the script loads. My home
network server, though, considers http://ip_address/ to be the root (I'm
guessing here), so if try to go back one directory it looks for a
page/file that doesn't exist.

Let me give an example:

A page on the live server is at www.mysite.com/news/page.htm.
The script (we'll use just one as an example) is at
www.mysite.com/scripts/menuscript.js.
The image file is at www.mysite.com/images/image.gif.

Let's talk about the .js file. When I call it from a page in the root
web I use:

<SCRIPT LANGUAGE="JavaScript" src="scripts/menuscript.js"></SCRIPT>

and that works, but it won't work when I call it from news/page.htm.
For that I use:

<SCRIPT LANGUAGE="JavaScript" src="../scripts/menuscript.js"></SCRIPT>

and that works. It's a bit of pain to have to use a different script
call depending on where the page lives, but it's manageable. The Jimco
add-in will not work for me here, because the calls have to be within
the <body> tag and Scripter puts them in the <head> tag.

What I can't fix is the calls to the image files. They get called from
within the .js file. The image files (and page URLs, too) are included
as part of variable declarations or whatever they're called. So, we're
finally to the part I can't figure out, and that's the syntax to use to
call these files so that it will look in the right place whether the
site is published to the live server at www.mysite.com or to the test
server at ip_address/mysite/

I tried to use a server-relative URL, as in /images/image.gif, and I
think that would work on the live server, but on the test server it
tries to find a file at ip_address/images/image.gif instead of at
ip_address/mysite/images.gif. The same thing happens if I use
.../images/image.gif. If I use an absolute URL it would have to be
different for each server.

I'm going to flatter myself and say I understand why each server behaves
as it does, but I can't think of a way to fix it. Is my test server
mis-configured? xammp configured it, but I could try to change it if
that would help. I actually think I know how to write and make it work
on the production server, but if I'm wrong the site will have no
navigation bars while I debug it, and I would get dirty looks from my
client, who also happens to be my wife.

Other than re-configuring the test server, is there maybe a way to
dynamically built the link called from the .js file by somehow examing
the server and then using JavaScript to concatenate strings to point
everything in the right direction? That sounds a little over my head,
but I thought I'd ask.

Thanks for reading this far. Comments welcome.

Randy



Randy Morgan
 
P

p c

For files in standard folders off the root you can use "absolute" path
from the base without incuding the domai. For example

/images/banner.gif
/styles/mystylesheet.css
/mystylesheet.css
/scripts/menuscript.js

The first / means off the root (base URL).

...Pc
 
R

Randy Morgan

My problem is more that the production and test servers have a different
root. When I use /images/banner.gif, for example, the browser gets
pointed one level higher on the test server. I'm afraid I must be out
of luck on this one, but there are other packages beside xampp so I
might find a way around it.

Thanks,
Randy Morgan
 
R

Randy Morgan

Whatever we call 'em, they work great on the production server but not
at all using xampp. Would I get away from this if I broke down and
upgraded the test server to XP Pro?

Randy Morgan
 
R

Ronx

Probably not. Your problem is that you are using a JavaScript menu
which requires root relative or absolute links to work in a multilevel
(folders) web site. Unless the web structure on the test machine is
identical to that on the production server the menu will not work on
both. In other words, you cannot use http://mysite.com/page.htm as
the web address on the production server unless you also use
http://ip_address/page.htm on the test server. This can be done using
IIS as well as with xampp - but you lose the flexibility of several
sites in folders such as http://ip_address/mysite/
Using IIS does enable you to use all the features in FrontPage.
 
P

p c

Randy,
if you want to try it at your own risk, it is possible to install IIS
onn Win XP HE. There are instructions here and smilar palces. It is not
recommended by MS but people have done it succesfully. If you decide to
try it, make sure you create a restore/recover point so that you can
restore back to it if the instructions take you the wrong way.

...PC
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top