Help me use the mysteries of DNS to trick Safari...

Discussion in 'macOS' started by bigandy, Jun 5, 2007.

  1. bigandy macrumors G3

    bigandy

    Joined:
    Apr 30, 2004
    Location:
    Murka
    #1
    I'm needing to finish off a web project I've been working on for a while, and I need to do it from home. However, having just moved house, I've not got any internets until the end of the month, and the deadline for this is Friday.

    I know I can configure a DNS service to mimic "www.site.com" to let Safari view the page as if it was connected to the tubes, when really it's accessing information on http://localhost/site/.

    The reason I need to do this is because parts of the site do not work correctly without absolute URLs (and I can't go and change them now).

    I did this once, years ago, on Windows, but can't remember how exactly. How would I go about doing this on MacOS?

    I'm currently half brain dead, so please make any response in an "idiots guide" manner.

    Thanks in advance.. ;)
     
  2. Mechcozmo macrumors 603

    Mechcozmo

    Joined:
    Jul 17, 2004
    #2
    Modify the hosts file on your Mac.

    This requires the Terminal and use (I believe) of the sudo command.

    Linkety

    You can always try TextEdit, and if that doesn't work, use the Terminal. Key thing to remember: backup first. That way, you can fix the damage you've done later.
     
  3. SC68Cal macrumors 68000

    Joined:
    Feb 23, 2006
    #3
    Why are you using absolute paths for your website is beyond me. That's a bad idea in my book.

    Relative paths make it less of a headache to go back and make changes.
     
  4. bigandy thread starter macrumors G3

    bigandy

    Joined:
    Apr 30, 2004
    Location:
    Murka
    #4
    Yeah, I had a mess with my hosts file previously but couldn't seem to fix the issue. I'll be trying again later...


    I understand that fully, however the site I'm having issues with was not created by myself, and consists of several thousand files - and I'm not changing it all. If I was being paid to I would, but I'm not. And the client understands this.
     
  5. localoid macrumors 68020

    localoid

    Joined:
    Feb 20, 2007
    Location:
    America's Third World
    #5
    If you wish to avoid terminal commands, you can edit your localhosts file via the Netinfo Manager (in Utilities) by navigating to: machine -> localhost
     
  6. fall3n macrumors 6502

    Joined:
    Aug 17, 2006
    #7
    I'm guessing you mean to setup Virtual hosts, yah?

    Basically you need to edit two files, this doesn't have to be done by Terminal. You need to edit your http.conf file (depending on your setup the file could be anywhere, the default location for the Mac installation is in your /etc/httpd/ folder)

    Then next file you need to edit is your hosts file. Also in /etc.

    To access /etc open Terminal and type

    defaults write com.apple.finder AppleShowAllFiles TRUE
    killall Finder

    do the same command but with FALSE to hide hidden files.

    Like I said depending on your setup things could be different, but here's what your http.conf file should look like at the very end of it. If nothing about virtual hosts is there, just add this.

    Code:
    #MY VIRTUAL HOSTS
    
    NameVirtualHost 127.0.0.1
    
    <VirtualHost 127.0.0.1>
    	ServerName localhost
    	DocumentRoot /Users/Username/Sites
    </VirtualHost>
    
    <VirtualHost 127.0.0.1>
    	ServerName www.sitename.dev
    	 ServerAlias sitename.dev *.sitename.dev
    	DocumentRoot /Users/Username/Sites/sitename
    </VirtualHost> 
    and finally your hosts file will look much like this
    Code:
    ##
    # Host Database
    #
    # localhost is used to configure the loopback interface
    # when the system is booting.  Do not change this entry.
    ##
    127.0.0.1	localhost
    255.255.255.255	broadcasthost
    ::1             localhost 
    
    127.0.0.1	www.sitename.dev 
    Alternately to your solution of using relative paths you could just open up BBEDIT and hit Find... and enter the absolute url to be replaced and the text to replace it, then hit Other... and select the folder of your site and hit Replace All. Then everything should be relative.
     
  7. bigandy thread starter macrumors G3

    bigandy

    Joined:
    Apr 30, 2004
    Location:
    Murka
    #8
    Exactly, but it doesn't seem to completely work.

    After trying all that (which I'd tried previously), restarting services, and screaming, it still doesn't work - Safari says "you're not connected to the internet" still, and Firefox just can't find anything.

    I may have to go that way, but with over 1000 files that could take a while, and waste away what time I do have, trying to fix someone else's issue. I'd much rather just get on with sorting the bit I'm meant to be doing.


    *curses*
     
  8. fall3n macrumors 6502

    Joined:
    Aug 17, 2006
    #9
    Hmm, just to clear things up. What exactly are you using? The pre-installed Apache that comes with Mac, an upgrade of this, a package like MAMP? When you type in localhost where does it go? does your Apache/PHP work? When you do php_info(); what do you get?
     
  9. dcv macrumors G3

    Joined:
    May 24, 2005
    #10
    I did this quite recently to test my website...

    BTW I'm running MAMP rather than the default OS X Apache server

    If your Apache server is running, stop it.

    Open up Terminal, type:

    Code:
    sudo pico /etc/hosts
    
    this should open your 'hosts' file for editing.

    Add a new entry:
    Code:
    127.0.0.1    dev.domainname.com
    
    save the file (Ctrl+X to exit will prompt to save)

    Next you need to edit the virtual hosts in your httpd.conf file

    If you're running MAMP you'll find this under /Applications/MAMP/conf/apache/

    Open it up and right at the bottom (section 3 is a section on Virtual Hosts)

    There should be a line in there like this:

    Code:
    # NameVirtualHost *
    
    Uncomment the line by removing the #

    Then add:

    Code:
    <VirtualHost *>
    DocumentRoot "/Applications/MAMP/htdocs/website"
    ServerName dev.domainname.com
    </VirtualHost>
    
    (obviously replacing the above with the correct path and domain names!)

    Save the file and restart the Apache server.


    How's that for an idiot's guide? Hope that helps :)
     
  10. Lixivial macrumors 6502a

    Lixivial

    Joined:
    Jan 13, 2005
    Location:
    Between cats, dogs and wanderlust.
    #11
    If, after following the other excellent sources/step-by-step how-tos here it's still not working:

    First try this command:

    Code:
    lookupd -flushcache
    And try accessing it again. If not, try this:

    If the hardcoded links are to a website that's actually live and available on the Internet it could be that lookupd is looking to the DNS entry and, finding its entry, trying to connect (even though you're not online). The point here is that you need to have the hosts file ahead of the DNS entry in the lookup order. Something which OS X does not do by default. Quoted/paraphrased from this source:

    In Terminal type in:

    lookupd -configuration

    The output will likely be lengthy look for this (there will be a number of LookupOrders, you want the one directly above _config_name: Host Configuration):

    LookupOrder: Cache NI FF DNS DS
    _config_name: Host Configuration

    If it's anything different follow these steps (In Terminal):

    Code:
    cd /etc
    sudo mkdir lookupd
    (Enter your administrator password)
    cd lookupd
    ls
    (If any files exist, make copies of them using the cp command.)
    cp hosts hosts.original
    sudo echo LookupOrder Cache NI FF DNS DS > hosts
    exit
    Restart and see if it takes effect.
     

Share This Page