Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Posted on
- Matthew Crouch
September 9, 2005, 1:48 pm
rate this thread
now I just need some tips on how to do this correctly and efficiently.
I usually have a head.inc and/or a constants.inc with definitions like
(SMARTY_DIR, APP_ROOT . "/smarty");
(ADMIN_DIR, APP_ROOT . "/admin");
I'm sure you get the idea, and I bet you have them too. Some of these go
fine, but many of them are all screwed up, esp. any dealing with
-CSS (the stylesheets never seem to get included until my fourth attempt
at writing the URL)
-images (sometimes ... it seems like different servers treat the initial
slash in src="/thingy.png" differently?)
Anyway, I always run into these snags in the midst of some project, and
I figure out a hacky thing to just make it work. Now I want to get
input/tutorial links, etc. on how to do this right:
-do src= (script and img), action= (in a form), and href= (in a normal
"<a" link, and in a <link stylesheet) have different behaviors, or am I
-should I just build absolute paths for everything?
All advice greatly appreciated. If there isn't a single, definitive
tutorial, I might build one based on feedback here.
Re: building a set of defined constants for application paths
Assuming you're talking about URLs in the HTML, then the server will
never see something of the form "/thingy.png". Your browser sees it and
converts it to an absolute URL before sending a request to the server.
The basic rules:
* Anything starting "http://" et al. is an absolute URL.
* An initial slash in a relative URL means "work from the domain root",
i.e. "/thingy.png" translates to "http://example.com/thingy.png",
regardless of what the current path is.
* Anything else is treated as relative to the path of the *current* page
as seen by the browser.
* "./" means "use the parent folder", so if you're at
http://example.com/foo/bar/index.html , then "./thingy.png", translates
This is described formally in RFC 1808.
No, they should all behave the same.
I would recommend not. It takes up more bandwidth to send (i.e. the HTML
file is bigger), makes the HTML harder to read (for humans, that is!),
and if you ever change domain or the root folder, then you'll have to
change all your links (unless you build the links dynamically).