Jump to content
Killersites Forums

relative path links in Wamp?


PicnicTutorials
 Share

Recommended Posts

Ran into another snag. My relative links in my includes are not resolving correctly. Live on my hosts server simply begining the url with "/" works perfect (eg /img/test.jpg). But not so in Wamp. I havn't tested this yet but I imagine if I were to use an absolute path or possibly my local directories full path (aka my computers path) it would work correctly. This is obviously not the optimal solution. I need to resolve this or I'm back at square one again. I did quite a bit of googling but couldnt find the solution. Have any of you ran into this or can you find the fix? Thanks!

 

This might possibly be due to the fact that I'm pointing wamp at my website files and they are not sitting in the wamp/www. directory. Possibly?

Edited by Eric
Link to comment
Share on other sites

That was a bit over my head. I literally read all day on my phone. Used a few hundred different search terms. It finally led me too needing to setup a Virtual Host. I followed this tut and now my links work exactly the same on my local testing as they do on my remote server. http://cesaric.com/?p=255

Link to comment
Share on other sites

Ran into another snag. My relative links in my includes are not resolving correctly. Live on my hosts server simply begining the url with "/" works perfect (eg /img/test.jpg). But not so in Wamp.

 

This might possibly be due to the fact that I'm pointing wamp at my website files and they are not sitting in the wamp/www. directory. Possibly?

 

Relative links do work in Wamp or from any other local directory PROVIDED that they aren't root-relative links like you have. If a link is a normal relative link like image.jpg or images/image1.jpg then it works locally but if you start with a / like /image.jpg or /images/image1,jpg the browser goes to the root directory and works from there, which is probably C:\ on your computer with lots of subdirectories before you reach the www directory so the file isn't found. On your host's server the root directory is the first you use.

 

So if you use root-relative links, always test online.

 

Edit: I've never set up a virtual host to use Wamp (but I normally use normal relative links, not root-relative links).

Edited by Wickham
Link to comment
Share on other sites

Relative links do work in Wamp or from any other local directory PROVIDED that they aren't root-relative links like you have. If a link is a normal relative link like image.jpg or images/image1.jpg then it works locally but if you start with a / like /image.jpg or /images/image1,jpg the browser goes to the root directory and works from there, which is probably C:\ on your computer with lots of subdirectories before you reach the www directory so the file isn't found. On your host's server the root directory is the first you use.

 

So if you use root-relative links, always test online.

 

Edit: I've never set up a virtual host to use Wamp (but I normally use normal relative links, not root-relative links).

 

Your right! I worded it wrong. When testing in Wamp and having it setup as an Alias relative links in my includes only worked at the root level. As soon as I needed that same include to display the code in a file outside the root it no longer worked. So I needed to use an absolute path (/). Absolute path only works with the Virtual Host setup. In the end almost just as easy. Just took a bit more time to figure out.

Link to comment
Share on other sites

Have you tried the <base> tag? You can temporarily set a base path for your relative links, perhaps drop it in your template, and when you go live you can easily take it out.

 

<base href="http://localhost/myProjectSite/" />

 

More info here: http://www.w3schools.com/TAGS/tag_base.asp

 

That would probably work too. Thanks!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...