0

I'm new to Apache. I'm trying to configure it on my localhost to do some testing. I've already deployed a PHP web site on Apache and it works well. My httpd-vhosts.conf is:

<VirtualHost *:80>
    DocumentRoot "C:\xampp\htdocs"
    ServerName shop.com
    ServerAlias www.shop.com
    ErrorLog "c:\temp\shop.com-error_log"
    CustomLog "c:\temp\shop.com-access_log" common
</VirtualHost>   

Also I added entries for shop.com and www.shop.com in hosts file. Now I can use shop.com to access my website. However, when the browser opens my web site, shop.com changed to localhost in the browser address bar. Is it possible to make browser still show shop.com while it actually serves files in C:\xampp\htdocs?

Just a learner
  • 26,690
  • 50
  • 155
  • 234

1 Answers1

0

You've to add www.shop.com and shop.com to the hosts file which is located in C:\Windows\system32\drivers\etc\hosts.

There you've to enter:

127.0.0.1 www.shop.com
127.0.0.1 shop.com

You need Admin-Access to change this file, and it might be required to switch off any Anti-Virus-program for saving. An exception in Anti-Virus is not good for this file because usually it's good that it's protected.

Additionally you could (and should) consider using another top-level domain for local development that the sites never collude with public available sites you want to visit perhaps. If you even serve your page to the public by allowing access to your pc or network it's possible that with the used top-level-domain "com" you can get some problems if the domain (shop.com) is not yours. Can start with friendly advises to close your server for the public but can be probably unfriendly and expensive too. I use always *.loc, that's clear, I saw others use *.dev as top-level-domain.

There is still one thing to mention: it's not common on every server that the domain is directly accessible without changing the hosts-file. So it's possible you entered the domain in a router that serves as DNS-Server or just in the local DNS-Server on your PC. You might need to adjust that too perhaps.

David
  • 5,882
  • 3
  • 33
  • 44