Fake domain with hosts file?

  • icecraft
  • Beginner
  • Beginner
  • icecraft
  • Posts: 38
  • Loc: New Hampshire, USA

Post 3+ Months Ago

Does anyone know if it's possible to use the hosts file to point a nonexistant
domain to another domain?

Example: myfakedotcom.com -> subdomain.cheapskate.com

I just want to simulate it during development without actually buying the domain. If not the hosts file, is there another way to do this?

Thanks in advance,
Logan
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • this213
  • Guru
  • Guru
  • User avatar
  • Posts: 1260
  • Loc: ./

Post 3+ Months Ago

If you want name to name mapping, you have to make an entry in your host file with the ip, something like:
Code: [ Select ]
192.168.0.5   myfakesite.com

and then you need to have the web server at 192.168.0.5 above answer requests to myfakesite.com by setting up a virtual host for that domain.

This is actually quite a bit of work to go through for just a development site (and you might forget to change it back later). A better answer would be to write your code so it uses relative names for links and includes.
PHP Code: [ Select ]
<?php
 
// instead of writing
 
echo '<a href="http://mysite.com/some_page.php">';
 
// you should be writing
 
echo '<a href="/some_page.php">';
 
 
 
// instead of writing
 
include('/var/www/html/somefile.php');
 
include('/var/www/protected/somefile.php');
 
// you should be writing
 
include('somefile.php');
 
include('../protected/somefile.php');
 
//or even - on Linux
 
$pwd = trim(`pwd`);
 
include($pwd.'/somefile.php');
 
$pwd = rtrim($pwd,basename($pwd));
 
include($pwd.'somefile.php');
 
?>
  1. <?php
  2.  
  3. // instead of writing
  4.  
  5. echo '<a href="http://mysite.com/some_page.php">';
  6.  
  7. // you should be writing
  8.  
  9. echo '<a href="/some_page.php">';
  10.  
  11.  
  12.  
  13. // instead of writing
  14.  
  15. include('/var/www/html/somefile.php');
  16.  
  17. include('/var/www/protected/somefile.php');
  18.  
  19. // you should be writing
  20.  
  21. include('somefile.php');
  22.  
  23. include('../protected/somefile.php');
  24.  
  25. //or even - on Linux
  26.  
  27. $pwd = trim(`pwd`);
  28.  
  29. include($pwd.'/somefile.php');
  30.  
  31. $pwd = rtrim($pwd,basename($pwd));
  32.  
  33. include($pwd.'somefile.php');
  34.  
  35. ?>

Those are all just examples, but you get the idea.
  • icecraft
  • Beginner
  • Beginner
  • icecraft
  • Posts: 38
  • Loc: New Hampshire, USA

Post 3+ Months Ago

Alright, thanks. It might have been worth it if it was just changing a line in the hosts file.

Fortunately my urls are relative so that's not the problem. I just wanted to use the actual domain to get a better feel for what it'll be like to use (the urls themselves have some significance to this site).

Thanks for replying.

Post Information

  • Total Posts in this topic: 3 posts
  • Users browsing this forum: No registered users and 64 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.