How to get custom domain names instead of localhost with xampp on windows

It is quite simple to turn your development urls like http://localhost/ibikri/ into http://ibikri.tes/ or http://ibikri.com/

It makes for a clean url when we are developing. And also allows you to work with actual urls instead of localhost or 127.0.0.1. This is quite handy for some situations.

Capture

Now before you begin, you should know what we are about to do

I am going to change windows hosts file to redirect that domain to localhost. So basically when you hit ibikri.com it would redirect you to localhost .This leads to a simple problem- “what happens if i wanna visit the actual ibikri.com?

This is why it is recommended to not use actual tlds on virtual hosts. Say instead of using ibikri.com you can use ibikri.localhost or ibikri.test or ibikri.vcom. It is upto you just try to avoid the tlds “*.dev  and *.foo” these tlds will not work with google chrome or firefox

I would recommend you see a this list of suggested domain extensions .

Step 1: Find and edit your hosts file. In windows it is located at

C:\Windows\System32\drivers\etc

Go to the bottom of the file and add this line

127.0.0.1 yourdomain.test

Here replace “yourdomain” with your sites domain duh!

Now in your apache folder find the httpd-vhosts.conf file for xampp it is located inside

xampp\apache\conf\extra\httpd-vhosts.conf

You should find a couple of tags in this file that is commented with ##. I recommend you copy 1 of those and uncomment it. And then replace the values. It would look something like this

This example is assuming your project is inside “yourfolder” inside xampp/htdocs. If it is inside htdocs directly just remove the /yourfolder

<VirtualHost yourdomain.test> 
    ServerAdmin webmaster@yourdomain.test 
    DocumentRoot "/xampp/htdocs/yourfolder"
    ServerName yourdomain.test 
    ServerAlias yourdomain.test 
    <Directory "C:/xampp/htdocs/yourfolder"> 
        Require local 
    </Directory> 
</VirtualHost>    

ok the reason why i recommend you copy one of your existing commented VirtualHost tag and edit it instead of copying this is the directory structure and syntax may be a little different in your version of apache.

 

We are done. Now just restart your apache server and you will be able to visit your local development server at localhost/yourfolder by typing

http://yourdomain.test/

in your browser.

Hope this helps someone. I learned how to do this from stackoverflow. If you want you could check this out, and this and maybe show them some gratitude by voting their answers :).

 

 

মন্তব্য করুন

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  পরিবর্তন )

Twitter picture

You are commenting using your Twitter account. Log Out /  পরিবর্তন )

Facebook photo

You are commenting using your Facebook account. Log Out /  পরিবর্তন )

Connecting to %s