ethar's avatar
Level 5

Virtual Host in Xampp Redirect to same url

I used Laravel, Xampp in windows 10 I created a virtual host

<VirtualHost *:80>
    DocumentRoot "C:/xampp/htdocs/site/hebron/public"
    Servername hebron
    ServerAlias www.hebron.test
    <Directory "C:/xampp/htdocs/site/hebron/public">
        Options Indexes FollowSymLinks
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

in hosts file

127.0.0.1	hebron.test 

until now it's working perfectly, but when creating another one

<VirtualHost *:80>
    DocumentRoot "C:/xampp/htdocs/site/blog/public"
    Servername blog
    ServerAlias www.blog.test
    <Directory "C:/xampp/htdocs/site/blog/public">
        Options Indexes FollowSymLinks
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

in hosts file

127.0.0.1 blog.test

the problem when visit blog.test , or hebron.test its redirect to same (hebron.test)

0 likes
7 replies
MarianoMoreyra's avatar

Hi @ethar

Try changing Servername in both cases to include the whole domain and the ServerAlias to *.domain

So you should have:

<VirtualHost *:80>
    DocumentRoot "C:/xampp/htdocs/site/hebron/public"
    ServerName hebron.test
    ServerAlias *.hebron.test
    <Directory "C:/xampp/htdocs/site/hebron/public">
        Options Indexes FollowSymLinks
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

and

<VirtualHost *:80>
    DocumentRoot "C:/xampp/htdocs/site/blog/public"
    ServerName blog.test
    ServerAlias *.blog.test
    <Directory "C:/xampp/htdocs/site/blog/public">
        Options Indexes FollowSymLinks
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

Also, just in case, change Servername to ServerName (with capital N) and remember to restart Apache.

1 like
SheldonCooper1's avatar

Hi everybody.

I am Laravel developer, I have no more than 2 years of experience. But I am passionate about software development and I want to become a better developer and person everyday. Currently I am involved with laravel but I'm open to other languages and technologies.

I try to practice as much as https://omegle.onl/ https://xender.vip/ I can, but you know, sometimes we need to talk and exchange information or knowledge with other people, but my friends are not software developers, and are not interested in learning this.

I heard from a chilean developer, that a good method for learning and improve your skills, is sharing and exchanging knowledge with other people. And I really think so.

I'd really enjoy if I could find a team, or create a team, with people with the same approach for learning together. I know there is people here possibly interested on this.

ethar's avatar
Level 5

thanks @marianomoreyra for your reply but still not working

httpd-vhosts.conf file

# Use name-based virtual hosting.
#
NameVirtualHost *:80
#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ##ServerName or ##ServerAlias in any <VirtualHost> block.
#
##<VirtualHost *:80>
    ##ServerAdmin [email protected]
    ##DocumentRoot "C:/xampp/htdocs/dummy-host.example.com"
    ##ServerName dummy-host.example.com
    ##ServerAlias www.dummy-host.example.com
    ##ErrorLog "logs/dummy-host.example.com-error.log"
    ##CustomLog "logs/dummy-host.example.com-access.log" common
##</VirtualHost>

##<VirtualHost *:80>
    ##ServerAdmin [email protected]
    ##DocumentRoot "C:/xampp/htdocs/dummy-host2.example.com"
    ##ServerName dummy-host2.example.com
    ##ErrorLog "logs/dummy-host2.example.com-error.log"
    ##CustomLog "logs/dummy-host2.example.com-access.log" common
##</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "C:/xampp/htdocs/site/hebron/public"
    ServerName hebron
    ServerAlias *.hebron.test
    <Directory "C:/xampp/htdocs/site/hebron/public">
        Options Indexes FollowSymLinks
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "C:/xampp/htdocs/site/blog/public"
    ServerName blog
    ServerAlias *.blog.test
    <Directory "C:/xampp/htdocs/site/blog/public">
        Options Indexes FollowSymLinks
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

hosts file

# For example:
#
#      102.54.94.97     rhino.acme.com          # source server
#       38.25.63.10     x.acme.com              # x client host

# localhost name resolution is handled within DNS itself.
127.0.0.1           localhost
#::1                 localhost
127.0.0.1			 hebron.test
127.0.0.1			 blog.test
MarianoMoreyra's avatar

@ethar check my previous answer again.

You still have ServerName without .test in both cases.

Please try changing them to:

ServerName hebron.test

and

ServerName blog.test

and see if that fix it

MarianoMoreyra's avatar

Hi @ethar

Did any of our last replies helped to solve your problem?

If it did, please consider to mark as answered so it will help others with same problem.

Thanks!

Please or to participate in this conversation.