Better URLs for Sites hosted on OSX?

Joined
Jan 24, 2007
Messages
2
Reaction score
0
Points
1
Hi,

I'm attempting to host a site on my machine while I work on it, but I'm running into (what I hope is a small) problem:

My site lives in my Sites directory, so the url is http://127.0.0.1/~nick/mysite.com

However, many of the pages in my site rely on URLs relative to the document root, expecting mysite.com to be the root. So, when I load up my site, all of my links and images break.

I've done a bunch of searching, but I can't seem to find the way to fix this. Can anyone offer any suggestions?

Many Thanks,
Nick
 
Joined
Apr 29, 2006
Messages
4,576
Reaction score
378
Points
83
Location
St. Somewhere
Your Mac's Specs
Mac Studio, M1 Max, 32 GB RAM, 2 TB SSD
I have done something like this with my site, which I developed in my Sites folder hierarchy, but then uploaded to the web hosting company I use.

Let assume the following hypothetical site layout

Main Page with two subpages, SubPage 1 and SubPage 2, both one level down from the Main Page

I have references in SubPage 1 to things in SubPage 2, and references in both to the main page. To make this completely portable, I have used relative paths.

So, for example, if I have a link in SubPage 1 called "SubPage2" that takes you to SubPage 2, the form of that link would be:

<a href="../SubPage2/subpage2.html">SubPage2</a>

In this way, all references are relative to the current position vs being absolute paths.

Does this help or have I missed your issue completely?
 
OP
N
Joined
Jan 24, 2007
Messages
2
Reaction score
0
Points
1
Thanks for your reply.

That helps, but doesn't quite solve my problem. The issue is that I need to be able to transfer files between my dev site on my computer and the live site, so the links need to work for both. Certain links in the templates (like stylesheet links and images in the header and footer) need to work from different points in the hierarchy, so relative paths won't work.

I imagine there's a way to do something with the Apache settings to basically clone a folder in the Sites directory as a root level folder (perhaps using symlinks, the hosts file, or .htaccess), but I haven't figured out how yet.

Any other suggestions?
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top