Image path, local host & offsite server

Posted on 2006-05-21
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

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
    LVL 9

    Accepted Solution

    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.

    LVL 12

    Author Comment

    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?
    LVL 9

    Expert Comment

    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

    Thanks again!
    LVL 12

    Author Comment

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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
    Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit ( and similar technologies have enjoyed wide adoption, making it possib…
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    The viewer will learn how to dynamically set the form action using jQuery.

    760 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

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now