Create absolute link to home directory in public_html folder

2.3k views Asked by At

I am trying to setup a test server to build websites in. I am using Ubuntu 14.04 with the public_html directory for each of my sites. So when I create a new site, I build a new user on the server and it creates all the necessary items for me (I also use the users directory to store information about that site as well) and I build the site in the public_html directory. To visit that site I go to http://testserver/~username. When I publish the site, it will be moved to a proper web server.

This works great, but when building the site in the public_html directory, all my absolute links must show as

<a href="/~username/page.php">Link</a>

How can I change it so that I can just make a normal absolute link, i.e.

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

and have it go to the proper page - testserver/~username/page.php?

I can use relative links as a work around, but I prefer using absolute links in my sites.

2

There are 2 answers

1
Barkermn01 On BEST ANSWER

You can't there part of the Browsers systems

http:// or https:// mean it's a fully qualified URL

/ means from the root of the domain

../ or pages/ relative to the current path of the URL

What i do is setup more subdomains

setup ~username.testserver/ and use each user as a domain. if you have an actual domain you can use the * as an A Record so that you dont have this problem

1
Akis On

Martin is right but you can use links in the way you wrote if you set up a vhost in your local web server with root directory your username folder.