0
votes

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!

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

1 Answers

1
votes

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.