Image path, local host & offsite server

Posted on 2006-05-21
Medium Priority
Last Modified: 2011-09-20
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
Server:  http://mysite.com/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.
Question by:UnexplainedWays
  • 3
  • 2

Accepted Solution

david_levine earned 2000 total points
ID: 16728183
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="http://mysite.com/content/" />

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="http://mysite.com/" />

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
server: http://mysite.com/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.

LVL 12

Author Comment

ID: 16728227
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?

Expert Comment

ID: 16728281
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.
LVL 12

Author Comment

ID: 16728441
Thanks again!
LVL 12

Author Comment

ID: 16728444
Oh an i did mean read files from the file system.

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Although a lot of people devote their energy toward marketing for specific industries, there are some basic principles that can be applied to any sector imaginable. We’ll look at four steps to take and examine how those steps were put into action fo…
Dramatic changes are revolutionizing how we build and use technology. Every company is automating, digitizing, and modernizing operations. We need a better, more connected way to work together as teams so we can harness the insights from our system…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question