tags:

views:

23

answers:

2

So this is my directory structure

/
/test
    index.php
    blah.php
blah.php

So in /test/index.php I have a link such as this

<a href="/blah.php">Link</a>

but I want it to link to /test/blah.php, not the blah.php in the root directory. Basically, I want to set a local document root. Is this possible to set this using .htaccess or in the httpd.conf?

A: 

Add this to your httpd.conf or better yet put it in a virtualhost directory

NameVirtualHost *:80

<VirtualHost *:80>
ServerName blah.localhost
DocumentRoot C:\web\test
</VirtualHost>

In WINDOWS\System\system32\etc\bin or somewhere ( LOOK for 'hosts' file ), edit hosts file so it has

127.0.0.1 blah.localhost

Restart apache and go to blah.localhost in the browser.

meder
A: 

If an a tag on /test/index.php has its href set to /blah.php, then it's the browser that's interpreting that as pointing to a file in the document root. So you can't achieve what you want without changing the way you're generating the href attribute.

You have a couple of options for this:

  • You can omit the forward slash to generate links relative to the current URL instead of the document root. A link in /test/index.php pointing to blah.php will be interpreted as /test/blah.php.

  • You can write some custom code to generate your links. You could have a function my_special_link ($link) that takes in blah.php and prepends the current file's directory, for example.

grossvogel