Image path, local host & offsite server

I'm developing a site on my localhost, this then get's uploaded to my hosting server.  However i have an issue with the image paths.

I've used the normal src="images/filename.gif" so it works in both the localhost and server.  (using master pages) when i create a subfolder, the images/filename.gif no longer works ( it's expecting a subfolder/images).

If i use the /images, this doesn't work on the local (because it goes back ot the localhost/images)

Local:  http://localhost/AppName/images/filename.gif

I have two current ideas on how to solve this.

1) Go to localhost on my pc and put the folders in there (but this defeats the purpose of different folders for different applications)

2) Create a folder on the server called AppName, and then use anything that has to be found from anyfile from the program.

Is there a better way to do this or are they my only options?  Thanks.
LVL 12
Who is Participating?
david_levineConnect With a Mentor Commented:
An option is to use a baseref command. What it does set the assumed default path to start any URL which does NOT start with a /. You could then edit just that one line or if possible create an include for each platform that has it differently and just not upload the include so it doesn't get overwritten.

This line goes in the HEAD section and looks something like...
<base href="" />

You'd have one referenced by your local development machine that would look like:
<base href="http://localhost/AppName/" />

and then on your server you'd have it look like:
<base href="" />

with an image reference in your source code of:
<img src="images/filename.gif">

would get referenced by the web browser as:
local: http://localhost/AppName/images/filename.gif

which I think is what you want. Just remember every reference that doesn't start with a / gets assumed to be using the baseref in front of it.

UnexplainedWaysAuthor Commented:
That pretty much does what i'm after.  I'll try to find a way to wack it into web.config to make one easy change.

On a side note, any idea how i could get this to work not just for <img>'s but also reading files?
What do you mean "reading files"? Do you mean hyperlinks to other URLs? They will honor the baseref tag. If you're talking about actually reading data files from the file system, you'd probably want a variable in web.config or whatever you're using that can do the same type of concept as baseref and modify your programming code to use that variable as the starting point like baseref does. The variable would be constant on each platform but different across your environments.
UnexplainedWaysAuthor Commented:
Thanks again!
UnexplainedWaysAuthor Commented:
Oh an i did mean read files from the file system.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.