Xammp Virtualhost Always Redirecting To htdocs - apache

Been stuck on this one for a little while now. Always get redirected to the index of htdocs.
I've ensured NameVirtualHost is un-commented.
Include conf/extra/httpd-vhosts.conf is un-commented.
I've tried changing the directives under the directory from;
Order allow, deny
Allow from all
To
Require all granted
I've restarted Apache multiple times, flushed DNS.
My files currently look like below;
httpd-vhosts.conf
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs"
ServerName localhost
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/development"
ServerName testsite.dev
ServerAlias www.testsite.dev
<Directory "C:/xampp/htdocs/development">
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
hosts
127.0.0.1 localhost
127.0.0.1 www.testsite.dev
Am I missing something? Any help would be greatly appreciated!

Related

When adding subdomain it's redirecting back to main domain

Have spent ages trying to figure this out, we're looking to add cloud.domainname.co.nz, the records are all setup, however when you search cloud.domainname.co.nz, it shows you the domainname.co.nz website, and not the one where the directory is set?
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs"
ServerName domain.co.nz
<Directory "C:/xampp/htdocs">
Options Indexes FollowSymLinks ExecCGI Includes
Order allow,deny
Allow from all
</Directory>
Redirect permanent / https://domain.co.nz/
SSLEngine on
SSLCertificateFile C:\xampp\apache\conf\domain.co.nz.crt
SSLCertificateKeyFile C:\xampp\apache\conf\domain.co.nz.key
SSLCertificateChainFile C:\xampp\apache\conf\domain.co.nz.ca-bundle
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/cloud"
ServerName cloud.domain.co.nz
ServerAlias cloud.domain.co.nz
<Directory "C:/xampp/cloud">
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
Have gone through many other peoples questions/answers and after trying those I still wasn't able to get it working properly, can't figure out why!!
I've also noticed people show their vhosts when trying to figure out similar issues so I've put it below..
127.0.0.1 cloud.localhost
127.0.0.1 domain.co.nz
127.0.0.1 cloud.domain.co.nz
I solve it by adding this to the virtual host configuration
NameVirtualHost *:80
NameVirtualHost *:443
<VirtualHost *:80>
DocumentRoot "D:/htdocs/"
ServerName localhost
</VirtualHost>
NameVirtualHost is so we can use the same port for multiple virtual hosts configurations. Setting up the usual domain for localhost is the key here. I am not sure why, but it solves the bug.

URL wont direct correctly

I have a problem with my vhost names. I am setuping a vhost in CentOS based OS. In the host file I added 2 vhost URL. And I also edit the httpd.conf file. I added the vhost directory. I restarted the httpd and I opened the URL in the browser. But it doesn't go to my page. It redirect to other page. Asking for hostnames. Here's my setup.
In my httpd.conf I have this:
<VirtualHost *:80>
DocumentRoot /data/APACHE/html/metro
ServerName store6.giftregistry.com.ph
ServerAlias store6.giftregistry.com.ph
<Directory "/data/APACHE/html/metro">
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /data/APACHE/html/metro
ServerName store7.giftregistry.com.ph
ServerAlias store7.giftregistry.com.ph
<Directory "/data/APACHE/html/metro">
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
In the hosts file I have this:
10.128.0.63 store6.giftregistry.com.ph
10.128.0.63 store7.giftregistry.com.ph
Is there a mistake with my code?
add
NameVirtualHost *:80
on top..
documentation :
http://httpd.apache.org/docs/2.2/vhosts/name-based.html

NameVirtualHost directive warning for Localhost

I have read through many posts and have configured WAMP for 2 sites on the same IP address as follows (httpd.conf extract):
#Tell Apache to identify which site by name
NameVirtualHost *:80
#Tell Apache to serve the default WAMP server page to "localhost"
<VirtualHost 127.0.0.1>
ServerName localhost
DocumentRoot "C:/wamp/www"
</VirtualHost>
#Tell Apache configuration for 1 site
<VirtualHost 127.0.0.1>
ServerName client1.localhost
DocumentRoot "C:/wamp/www_client1"
<Directory "C:/wamp/www_client1">
allow from all
order allow,deny
AllowOverride all
</Directory>
DirectoryIndex index.html index.php
</VirtualHost>
#Tell Apache configuration for 2 site
<VirtualHost 127.0.0.1>
ServerName client2.localhost
DocumentRoot "C:/wamp/www_client2"
<Directory "C:/wamp/www_client2">
allow from all
order allow,deny
AllowOverride all
</Directory>
I have also changed the Windows hosts file to add 127.0.0.1 client1.localhost etc. however when I restart the WAMP services, //client1.localhost and //client2.localhost go to the default site in the c:\wamp\www folder.
Any help really appreciated.
Have you included your vhosts.conf in your httpd.conf?
Uncomment this line (the one that starts with 'Include') near the bottom of httpd.conf:
# Virtual hosts - leave this commented
Include conf/extra/httpd-vhosts.conf
Edit:
It looks like the problem is that NameVirtualHost and VirtualHost have to match, so you can't have NameVirtualHost *:80 and VirtualHost 127.0.0.1. Instead, use NameVirtualHost *:80 and VirtualHost *:80 or NameVirtualHost 127.0.0.1:80 and VirtualHost 127.0.0.1.
If they don't match, you will see the behavior mentioned in your comment where either the virtual host that doesn't match the others will get hit, or if they are all the same, the first on (your default localhost) will get hit.
See this post for more: Wamp Server: Multiple Virtual Hosts are not working on Windows
Try this configuration, its just a few minor mods to yours
#
# Use name-based virtual hosting.
#
NameVirtualHost *:80
## must be first so the the wamp menu page loads
<VirtualHost *:80>
ServerAdmin webmaster#homemail.net
DocumentRoot "C:/wamp/www"
ServerName localhost
ServerAlias localhost
<Directory "C:/wamp/www">
Order Deny,Allow
Deny from all
Allow from 127.0.0.1
</Directory>
</VirtualHost>
#Tell Apache configuration for 1 site
<VirtualHost *:80>
ServerName client1.localhost
DocumentRoot "C:/wamp/www_client1"
<Directory "C:/wamp/www_client1">
AllowOverride All
order Allow,Deny
Allow from all
</Directory>
DirectoryIndex index.html index.php
</VirtualHost>
#Tell Apache configuration for 2 site
<VirtualHost *:80>
ServerName client2.localhost
DocumentRoot "C:/wamp/www_client2"
<Directory "C:/wamp/www_client2">
AllowOverride All
order Allow,Deny
Allow from all
</Directory>

NameVirtualHost causes 404 for localhost

I've managed to setup several VirtualHosts by enabling NameVirtualHost. Here's the top part of my vhosts.conf
NameVirtualHost *:80
<VirtualHost *:80>
ServerName mysite.local
...
</VirtualHost>
The problem is when I visit http://localhost I get the default "It works!". If I go to http://127.0.0.1/ it defaults to http://mysite.local
I understand from the Apache Docs that why it defaults to mysite.local (matching the first VirtualHost). But I used to be able to go to http://localhost/phpmyadmin/.
How can I get this back? Do I need to make my first VirtualHost localhost? That seems wrong...
Running apache 2.2.15 on Mac OS X (10.6.6).
UPDATE
If I comment out the following lines from my hosts file, both localhost and 127.0.0.1 go to the same place. I verified in the access log that it was indeed using ::1.
::1 localhost
fe80::1%lo0 localhost
So I suppose that handles the first issue, provided this is okay? But how can I get localhost to go to my default DocumentRoot?
How can I get this back? Do I need to make my first VirtualHost localhost? That seems wrong...
I did it like this and all seems to be working just fine, without needing an extra port to listen on.
The first VirtualHost block
handles any URL that doesn't point to one of the 2 vhosts (2nd and 3rd VirtualHost blocks) I have set up:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot "/Applications/XAMPP/xamppfiles/htdocs/"
ServerName localhost
ServerAlias localhost
</VirtualHost>
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot "/Applications/XAMPP/xamppfiles/htdocs/imputation/dirmaster/http/"
ServerName imputation.loc
<Directory "/Applications/XAMPP/xamppfiles/htdocs/imputation/dirmaster/http/">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot "/Applications/XAMPP/xamppfiles/htdocs/documentatiebestand/"
ServerName documentatiebestand.loc
<Directory "/Applications/XAMPP/xamppfiles/htdocs/documentatiebestand/">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
No, you can't mix VirtualHosts with "classic" configuration.
You could listen on another port and define another VirtualHost (*:8080 for example) "emulating" your previous "localhost" going to your general DocumentRoot declaration.
Something like this:
Listen 80 (already declared elsewhere)
Listen 8080
NameVirtualHost *:80
NameVirtualHost *:8080
<VirtualHost *:80>
ServerName mysite.local
...
</VirtualHost>
<VirtualHost *:8080>
ServerName localhost
DocumentRoot /same/as/the/classic/one/
...
</VirtualHost>
You could also declare some Alias /phpmyadmin/ which would be global be I don't recommend aliases because you couldn't have another phpmyadmin folder in one of your vhosts.
You can of course define a phpmyadmin.local vhost ;-)

Having trouble with multiple hosts on Apache Snow Leopard

I am running Apache on my Mac OS X (Snow Leopard) machine. I want to be able to set up multiple hostnames so that I can develop and test multiple sites at the same time, but I can't seem to get this to work.
Here's what I've tried:
In my etc/hosts file I've set added these entries:
127.0.0.1 testsite1.localdev.com
127.0.0.1 testsite2.localdev.com
Then, in apache2/httpd.conf I have added these entries:
<VirtualHost *:80>
DocumentRoot /Library/WebServer/Documents/www/development/testsite1
ServerName testsite1.localdev.com
<Directory "/Library/WebServer/Documents/www/development/testsite1">
AllowOverride All
Allow from All
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /Library/WebServer/Documents/www/development/testsite2
ServerName testsite2.localdev.com
<Directory "/Library/WebServer/Documents/www/development/testsite2">
AllowOverride All
Allow from All
</Directory>
</VirtualHost>
But happens is that both hostnames resolve to the first one listed in the httpd.conf file -- in this case, testsite1. If I switch their positions, then they both resolve to testsite2.
I've also tried changing the area that reads *:80 and replacing that with the specific hostnames for each site, but that has no effect.
I am being sure to reboot apache after each change.
Thanks for any help!
Gary
in /etc/apache2/httpd.conf uncomment the vhost file like:
# Virtual hosts
Include /private/etc/apache2/extra/httpd-vhosts.conf
in /private/etc/apache2/extra/httpd-vhosts.conf use...
#
# Use name-based virtual hosting.
#
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot "/Library/WebServer/Documents"
ServerName localhost
</VirtualHost>
# local test site
<VirtualHost *:80>
<Directory /Users/<youruser>/Sites/test>
AllowOverride All
</Directory>
DocumentRoot "/Users/<youruser>/Sites/test"
ServerName test.local
</VirtualHost>
Be sure that your and Sites folders have permissions of 755
and be sure that you add to your /etc/hosts file...
# test
127.0.0.1 test.local