João Pedro Mantovani João Pedro Mantovani - 2 months ago 13
Apache Configuration Question

/Localhost is redirecting to a inside htdocs folder instead the root

When I access my localhost (or 127.0.0.1) by browser I got redirect to a folder inside the root. For example:

I started my xampp, go to the browser and put 127.0.0.1 instead being redirect to the htdocs root to see all my folders (projects), I'm redirect to an existing folder and can't access the anothers projects.

Anybody knows how to fix this? I searched a lot of question here but the all problems is to redirect to another folder instead of the root folder. I already checked my httpd.conf:

ServerRoot "C:/xampp/apache"

<Directory "C:/xampp/htdocs/">


After moving away my folder from the htdocs, I received the following message from the browser:

Object not found. Error 404.

Edit

I restarted my computer and not started the xampp. I can access my localhost anyway.

Answer

Check your hosts file for some redirections

Then you can do the next (as i do for my local projects):

  1. Create folder named localhost inside htdocs and put all standart files there

  2. create folder mynewproject.local and put some your .php there

  3. Now go to xampp/apache/conf/extra and open httpd-vhosts.conf and write

VirtualHost *:80>

DocumentRoot "C:\xampp\htdocs\localhost"
ServerName localhost

/VirtualHost>

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    DocumentRoot "C:\xampp\htdocs\mynewproject.local"
    ServerName mynewproject.local
    ErrorLog "logs/mynewproject.local-error.log"
    CustomLog "logs/mynewproject.local-access.log" combined 
</VirtualHost>
  1. Open your hosts file and add

    127.0.0.1 mynewproject.local

Now you can acces your project via mynewproject.local and localhost via localhost

Comments