0

first post on stackoverflow!

Been at this for hours and can't figure it out.

Wamp is installed to C:\wamp, website is in C:\wamp\www\groovysite.net and displays in my browser at localhost/groovysite.net.

There is a subfolder groovysite.net/subfolder. The problem is that all relative urls in pages contained in the subfolder are adding the subfolder into the url path just after the root folder.

For example two stylesheets live in

C:/wamp/www/groovysite.net/stylesheets/app.css
C:/wamp/www/groovysite.net/style.css

In my site's head is

<link rel="stylesheet" href="stylesheets/app.css" />
<link rel="stylesheet" href="style.css">

On the hompepage groovysite.net/index.html the url paths are

localhost/groovysite.net/stylesheets/app.css
localhost/groovysite.net/style.css

so they work. But on subfolder/page.html the paths are

localhost/groovysite.net/subfolder/stylesheets/app.css
localhost/groovysite.net/subfolder/style.css

so it seems like WAMP is sticking the subfolder path onto the relative urls.

I read that setting up virtual hosts directs WAMP to find the correct document root for each virtual host and that would sort this issue out. To that end this is my current configuration on apache 2.4.9:

Hosts file:

127.0.0.1 localhost
::1  localhost

127.0.0.1 groovysite.net
::1  groovysite.net

httpd.conf virtual hosts line is uncommented

httpd-vhosts.conf

<VirtualHost *:80>
    DocumentRoot "c:/wamp/www"
    ServerName localhost
    ServerAlias localhost
    ErrorLog "logs/localhost-error.log"
    CustomLog "logs/localhost-access.log" common
    <Directory  "c:/wamp/www">
        AllowOverride All
        Options Indexes FollowSymLinks
        Require local
    </Directory>
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "c:\wamp\www\groovysite.net"
    ServerName groovysite.net
    ServerAlias www.groovysite.net
    ErrorLog "logs/groovysite.net-error.log"
    CustomLog "logs/groovysite.net-access.log" common
    <Directory  "c:/wamp/www/groovysite.net">
        AllowOverride All
        Options Indexes FollowSymLinks
        Require local
    </Directory>
</VirtualHost>

Code was taken from RiggsFolly's answer here.

Completely stumped...any help would be greatly appreciated!

Community
  • 1
  • 1
  • 1
    This is nothing to do with wamp, that's exactly how relative links are supposed to work... Root them to the correct place and your issue should disappear. – arco444 Dec 09 '14 at 14:10

1 Answers1

1

A couple of suggestions

This line

DocumentRoot "c:\wamp\www\groovysite.net"

Should be

DocumentRoot "c:/wamp/www/groovysite.net"

Its not the solution but you should use unix seperator and not dos seperators.

Most important, is that you should be running the site using the domain name you created in the Virtual Host definition i.e.

http://groovysite.net 
or 
http://www.groovysite.net` 

and NOT

`http://localhost/groovysite.net`

Thats the whole point of creating a virtual host! If you dont do that then Apache wont pickup the virtual host definition and wont use the correct DocumentRoot, hence the incorrect additions to your links.

Also this post is probably more complete, check the bottom for the section entitled How do I turn this other 'My Virtual Hosts' menu on?

Also make sure you did not follow any advice that suggested changing \wamp\www\index.php to amend the line to

$suppress_localhost = false;

If you leave this as

$suppress_localhost = true;

Then with your Virtual Hosts defined the project links on the WAMPServer homepage should launch your Virtual Host properly and not add the localhost to the front of the url.

Community
  • 1
  • 1
RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
  • Checked index.php and that's not edited. Reading my question I realize that I failed to mention that navigating to http://groovysite.net in the browser currently puts me at the wampserver homepage. groovysite.net is listed under projects with the other folders in c:/wamp/www but I can't get to the folder's index page by clicking the link on wamp's homepage or by typing http://groovysite.net. I need to type localhost/groovysite.net to see the index page. Pretty sure this is not the way it's meant to work, thus why I feel like it has something to do with the virtual host setup. – woodwork3r Dec 09 '14 at 18:23
  • Did you change the DocumentRoot as mentioned in my answer? – RiggsFolly Dec 09 '14 at 18:31
  • I did...no luck initially after restarting wamp and dns. Closed everything out, rebooted, it works! Thanks a bunch for your help – woodwork3r Dec 10 '14 at 06:08
  • @woodwork3r, please mark this as the solution if it answered your question. – Sablefoste May 30 '17 at 12:51