web site root

Discussion in 'Web Design and Development' started by Dunmail, Feb 16, 2010.

  1. Dunmail macrumors regular

    Joined:
    Mar 27, 2009
    Location:
    Skipton, UK
    #1
    I'm trying to solve a problem with the root of my website when testing in OS X.

    I've a link on every page to the home page like "/index.php' which will work on a full web server but on my local system it goes to http://localhost.

    No doubt it's something simple to set up but I seem to be suffering a brain f**t at the moment :eek:
     
  2. Darth.Titan macrumors 68030

    Darth.Titan

    Joined:
    Oct 31, 2007
    Location:
    Austin, TX
    #2
    I'm not understanding the problem. http://localhost is the root of your local server, the same as /index.php.

    Is there a particular problem with your site on your local server that you're experiencing?
     
  3. Makosuke macrumors 603

    Joined:
    Aug 15, 2001
    Location:
    The Cool Part of CA, USA
    #3
    If I understand correctly, Dunmail wants to locally preview a site using absolute URLs (or semi-absolute; whatever you call things referenced to the server root as /).

    I don't believe it's possible to easily do this with straight file:// access, but the quickest method I'm aware of is:

    1. Turn on Web Sharing in the Sharing preference pane, so Apache is running
    2. Then put your site in the default Apache root folder, located at /Library/WebServer/Documents/ on your system drive.
    3. Now when you go to http://localhost/ you should get the contents of that folder served to you, and URLs starting with / will work properly.

    There will be some default Apache pages there, which you can delete. It will also properly serve default index.html pages without having to explicitly state the filename in the URL, which doesn't work with the file schema. You can also turn on PHP or SSI or other scripting languages to preview dynamically generated content live this way, since it's being served via a full Apache.

    You could also set your computer up to handle virtual hosts if you wanted to preview multiple sites, but that's getting more complicated.
     
  4. Dunmail thread starter macrumors regular

    Joined:
    Mar 27, 2009
    Location:
    Skipton, UK
    #4
  5. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #5
    I suggest looking at VirtualHost as a solution. It's what I use to test multiple sites locally using one instance of Apache.
     
  6. digitalField macrumors regular

    Joined:
    May 21, 2004
    Location:
    portland
    #6
    It sounds like you just need a refresher on Relative Linking http://www.webreference.com/html/tutorial2/3.html

    once you know where your base url is.. you should be able to construct relative links in your various index pages that all reference back without having to rewrite them each time.

    M
     
  7. Cerebrus' Maw macrumors 6502

    Joined:
    Mar 9, 2008
    Location:
    Brisbane, Australia
    #7
    I think the OP is talking mainly about the / operator to stay within his 'local' directory, rather then building a relative href each time. This would help with deployment of individual sites which are under one domain. If he was to use relative URLl each time, once that 'local directory' became its own full blown domain, he would eithe r have to rewrite the href's or change hte structure of his site.

    @OP: I second Angel's suggestion and go with Virtual Host. Other then that, I'm pretty sure your request can be achieved by .htaccess, but this would be slightly more difficult.
     
  8. ChicoWeb macrumors 65816

    ChicoWeb

    Joined:
    Aug 16, 2004
    Location:
    California
    #8
    Are you using cPanel? If so, your home dir is:

    Code:
    /home/username
     
  9. Dunmail thread starter macrumors regular

    Joined:
    Mar 27, 2009
    Location:
    Skipton, UK
    #9
    Releative linking is the exact opposite of what I'm after - I'm after an absolute link to the root of the current site when testing on OS X. On a shared host href="/" is mapped to "public_html" or whatever the particular setup decides to call it, i.e. the root of the website - I wish to do the same on my home machine.

    It looks like virtualHost is the way to go.
     
  10. NoNameBrand macrumors 6502

    Joined:
    Nov 17, 2005
    Location:
    Halifax, Canada
    #10
    Virtual hosting is the only thing that will do what you want. That's how shared hosts do it.
     

Share This Page