using ...src="/images/..." gets localhost instead of virtual directory on IIS

i have a virtual directory in IIS called "bob" which is installed in my c:\inetpub\wwwroot\clients\bob folder

when i use <img src="/images/image.jpg"> it points all the way back to localhost instead of the virtual root "bob". i realize that using the forward slash at the beginning of src is doing this, but my intention is to have it look at the root. do i need to configure IIS in some way to have it point to "bob/images" instead of "localhost/images"?
LVL 4
Jeremy DaleySenior DeveloperAsked:
Who is Participating?
 
Jeremy DaleySenior DeveloperAuthor Commented:
i actually ended up downloading a program called iisadmin that allows you to create multiple sites on windows xp professional (only 1 can be running at a time). the site root then became the correct root as i initially wanted.
0
 
kurtfarrarCommented:
If you're using ASP.NET and it's a server side control you can use the tilda ~ to signify the root of your application.

For example, if your application was in the virtual directory: http://localhost/bob

Then saying <asp:Image ImageUrl="~/images/Logo.gif" alternativeText="" /> would always display the image at http://localhost/bob/images/Logo.gif regardless of whether your page was in http://localhost/bob
or
http://localhost/bob/subdir1/subdir2/subdir3/subdir4

Also, if you then moved your application to a different virtual directory: http://localhost/harry/potter the url for the logo would automatically work with that as the new root... ie. it would look for the logo at http://localhost/harry/potter/images/Logo.gif.

I realise you're using PHP, but this may be some help to move to .NET? :o)

Hope this helps!
0
 
Jeremy DaleySenior DeveloperAuthor Commented:
i actually program in both PHP and .NET (C#), but to convert this site would be too tedious of a task. it will work fine once i upload it over to the actual host, but i'd like to test in on localhost first.

i guess this is more of an IIS issue than PHP, by the way it uses relative paths on virtual directories.
0
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

 
kurtfarrarCommented:
I think it's more likely to be a restriction of HTML rather than specifically PHP. .NET just works around the issue by allowing you to code something which represents 'root of app', and then at runtime, it figures out what the root is and translates it.

Viewing the HTML output of a page in http://localhost/bob/ which uses ~/images/logo.gif would show the image source as http://localhost/bob/images/logo.gif, not a normal relative path but instead an absolute URL.

It's been a while since I've coded in PHP, but you could create a function which does the same as the .NET tilda does... pop it in an file and include that one your pages that need to use the function. The function would return the root location of the website... I'd hope there's a way either view the request/response objects, or through an already existing PHP function to get the web-root? You may need to do some parsing, but at least if it's done in the function you're not having to recode that over and over.
0
 
Jeremy DaleySenior DeveloperAuthor Commented:
IIS on Windows XP Pro natively only allows you to create one site (localhost). If I was able to create a new site instead of just a virtual directory under "localhost", the preceeding forward slash would then take me to its root.

I just hope this doesn't require me to buy Windows Server 2003...
0
 
kurtfarrarCommented:
For testing/evaluation purposes you could always get an evaluation Virtual Hard Disk from:
http://www.microsoft.com/downloads/details.aspx?familyid=77f24c9d-b4b8-4f73-99e3-c66f80e415b6&displaylang=en

It'd allow you to run Windows 2003 Server to see if it does sort things for you before buying... if you did eventually have to.

Sorry I'm no further help.
0
 
nplibCommented:
if the virtual dir is Called "Bob" then that is the start of the ref point if you want to reference anything in it.

<img src="bob/images/image.jpg">
0
 
Jeremy DaleySenior DeveloperAuthor Commented:
yes, but an included file is used in all pages "header.php"... and that means used in all other underlying directories (bob/states/ohio/somepage.php).

so <img src="bob/images/image.jpg"> would no longer be coming from the root "bob", but instead:
bob/states/ohio/bob/images/

make sense?
0
 
nplibCommented:
Well this is the first you mentioned an include file,

Can you post all code?
0
 
kurtfarrarCommented:
You could always add a constant variable to your header.php file with the root... in essence the equivalent of putting the root address in the web.config?
0
 
Vee_ModCommented:
Closed, 500 points refunded.
Vee_Mod
Community Support Moderator
0
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.