Search code examples
laravelxampp

How to set local host in 127.0.0.1


There’s something I don’t understand about my laravel project. I’m using xampp. When I write https://localhost in my browser, it takes me to my web page, but if instead of writing localhost I write https://127.0.0.1 it takes me to laravel dashboard and not my web page. I don’t know why that happens. Does anyone know why it happens? Thank you.


Solution

  • The difference is the Host header that the browser sends. When you go to http://localhost, it'll send:

    Host: localhost
    

    but when you go to http://127.0.0.1, it'll send:

    Host: 127.0.0.1
    

    The server uses the Host header to figure out what content to reply with, since the same server can be serving multiple websites with different domains and different document roots.

    Apparently your server (probably via your Laravel configuration in your specific case) is set up to handle a host called localhost, but not one called 127.0.0.1.