How to add a Custom Domain in Windows WAMP Server Localhost
How to add a Custom Domain in Windows WAMP Server Localhost
Navigate to ‘C:\Windows\System32\drivers\etc‘
You’ll find ‘hosts’ file amongst other files. The directory structure in Command Prompt && Powershell appears like;
Directory: C:\WINDOWS\System32\drivers\etc\
Length Name
39 hosts
705 hosts.ics
3683 lmhosts.sam
407 networks
1358 protocol
17635 services
In Windows file manager, the directory structure is like;
Open ‘hosts’ file with your preferred code editor; Notepad, Atom, etc.
Inside of ‘hosts’ you will most likely find the following, unless you or someone else who has possessed or owned your Windows machine, has previously modified the ‘hosts’;
#
127.0.0.1 localhost
::1 localhost
Your ‘hosts’ file may not be this short, due to some of the reasons listed above. But there is no need to worry, you can operate with the file ‘as-is’ or you can make changes you see fit to the file (the latter requires technical knowhow, so novice users shouldn’t change it unless they are sure they want to).
Adding Code To ‘hosts’ file
Add the following lines of code to add a Custom Domain to your Windows machine, a Domain that will still use the default localhost IP, 127.0.0.1;
127.0.0.1 ***.***.***
Note that ‘***‘ should be replaced with the actual domain sections you want as shown in the example below.
Here you can add more than one domain name, and you could even remove localhost if you do not wish to use it as one of the domains.
Below is an example of adding multiple domains while still using localhost IP. The following lines of code are what the final ‘hosts’ file will look like after making necessary changes;
#
127.0.0.1 localhost
::1 localhost
127.0.0.1 www.testdomain.org
127.0.0.1 testdomain.org
127.0.0.1 testdomain
Now, if you launch your local WAMP Server, you should be able to access the index files – index.php && index.html files by just typing the custom domains you just added, just by; Opening your Browser && Entering the custom domain address in the browser’s address bar.
If you access your website via HTTPS, you will not have any trouble getting to your site’s landiing page. However, if you access the website via HTTPS and you haven’t created a self-signed certificate and you haven’t set your domain to be accessible only via HTTPS, your site should be accessible in a few more steps.
After entering your website’s address in your browser and hitting Enter, most likely you will land on an error page, and by clicking on ‘Advanced…‘ button in your Firefox/Chrome browser and then clicking ‘Accept the Risk and Continue‘ you will land in the UI (User Interface) of your website.
If you have enabled SSL in your local web server, created a Self-Signed Certificate and your browser uses HSTS, Note that the domains with the format ‘***.***.***‘ may not result in the target index files in the root of your ‘www‘ root directory in certain browsers, including but not limited to; Mozilla Firefox && Google Chrome.
These two browsers may in response to these domains throw an exception concerning ‘HSTS – HTTP Strict Transport Security’
Firefox Exception Example (At the time this article was published, Firefox version used was Version 75.0 (64 bit)). The following is a common Self-Signed Certificate exception in Firefox;
“””
www.testdomain.org has a security policy called HTTP Strict Transport Security (HSTS), which means that Firefox can only connect to it securely. You can’t add an exception to visit this site.
www.testdomain.org uses an invalid security certificate.
The certificate is not trusted because it is self-signed.
Error code: MOZILLA_PKIX_ERROR_SELF_SIGNED_CERT
View Certificate
“””
Chrome Exception Example (At the time this article was published, Chrome version used was Version 80.0.3987.163 (Official Build) (64-bit) ). The following is a common Self-Signed Certificate exception in Chrome;
“””
Your connection is not private
Attackers might be trying to steal your information from www.testdomain.org (for example, passwords, messages, or credit cards). Learn more
NET::ERR_CERT_COMMON_NAME_INVALID
“””
Both of the above exceptions are very common and they pop up in case you use a Self Signed Certificate with either Firefox and Chrome.
Solution to SELF-SIGNED CERTIFICATE Exception;
To solve the problem, use the custom domain you set without the top-level domain && hostname, e.g. ‘testdomain‘ instead of ‘testdomain.org‘ or ‘www.testdomain.org‘. In the event that you had not set the custom domain stripped off the top-level domain && hostname, refer to the above ‘Adding Code To ‘hosts‘ file’ section.
How to add a Custom Domain in Localhost
Hacking | thetqweb