user813720
user813720

Reputation: 451

how to define a virtual root?

The root of my local server is /Users/myname/Sites and all web projects are in seperate directories in that e.g. /Users/myname/Sites/newproject

The problem I've got is I've got a site which has all html paths written beginning with a slash e.g <a href="/dir/file.txt"> which makes the browser look for the file file.txt in /Users/myname/Sites/ rather than in /Users/myname/Sites/newproject where the file is located.

Rather than edit every single file path to either remove the beginning slash or to put in a php variable at the start I was wondering if there was some easy way to do this site wide?

I've tried using <base href="http://localhost/newproject" />

I've tried setting the DocumentRoot in .htaccess

I've tried setting the $_SERVER['DOCUMENT_ROOT'] to $_SERVER['DOCUMENT_ROOT']."/newproject";

Unfortunately none of these seem to work.

Upvotes: 0

Views: 650

Answers (2)

alxbl
alxbl

Reputation: 790

You want to setup a virtual host (if you are using apache) to specify that the / url should map to /User/myname/Sites/newproject.

You would do this like so (edit httpd.conf or place a file in conf.d):

# Listen for virtual host requests on all IP addresses, port 80
NameVirtualHost *:80

<VirtualHost *:80>
DocumentRoot /User/myname/Sites/newproject
ServerName localhost

</VirtualHost>

Note that when you do this, you are essentially "setting document root to be your newproject folder", which will shadow everything else in the Sites folder.

If this is not what you are talking about, please let me know so I can modify my answer.

Upvotes: 2

chiborg
chiborg

Reputation: 28094

You can try setting up a virtual host. Assuming from your folder structure that you are on Mac OS X, try this:

http://mark-kirby.co.uk/2008/setting-up-virtual-hosts-on-os-x-leopard

Upvotes: 1

Related Questions