You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Geoff Millikan <gm...@t1shopper.com> on 2011/06/02 01:05:59 UTC

[users@httpd] Special configuration for requests that do not match any particular virtual host? Apache 2.2

I want to make a catch-all virtual host (like the manual mentions below) which redirects any errant hostnames like
http://oopsie.mydomain.com/ to our main hostname at http://www.mydomain.com/   But the below example doesn't work - I'm getting an
infinite redirect from http://www.mydomain.com/ right back to http://www.mydomain.com/ 

What am I missing?

#First virtual host entry
<VirtualHost *:80>
	RewriteEngine On
	RewriteRule 	.* http://www.mydomain.com%{REQUEST_URI} [L,R=301]
	ErrorLog 	/var/log/httpd/error_log
	CustomLog	/var/log/httpd/access_log combined
</VirtualHost>

#Second virtual host entry
<VirtualHost *:80>
	ServerName	www.mydomain.com
	DocumentRoot   /home/mydomain/www
	<Directory /home/mydomain/www>
		Options -ExecCGI +FollowSymLinks +IncludesNOEXEC -Indexes -MultiViews +Includes
		AllowOverride None
	</Directory>
	ErrorLog 	/var/log/httpd/error_log
	CustomLog	/var/log/httpd/access_log combined
</VirtualHost>

http://httpd.apache.org/docs/2.2/vhosts/name-based.html - "If you would like to have a special configuration for requests that do
not match any particular virtual host, simply put that configuration in a <VirtualHost> container and list it first in the
configuration file."


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


RE: [users@httpd] Special configuration for requests that do not match any particular virtual host? Apache 2.2

Posted by Geoff Millikan <gm...@t1shopper.com>.
>> Without the ServerName, the vhost entry matches everything.
>
> Everything, or the ServerName defined globally?

<foot_in_mouth>

You're right, good catch.  Without the ServerName, the vhost entry matches only whatever the ServerName is defined as globally
(which is the ServerName outside any <VirtualHost> containers).

Boy, I owe a lot of people beer.

</foot_in_mouth>




---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Special configuration for requests that do not match any particular virtual host? Apache 2.2

Posted by Eric Covener <co...@gmail.com>.
On Thu, Jun 2, 2011 at 5:02 PM, Geoff Millikan <gm...@t1shopper.com> wrote:
> Poop.  It's a simple oversight.  Sorry everyone.  Tom Evans example works just fine.  The example from the original post would have
> worked with the addition of a *ServerName*.  Without the ServerName, the vhost entry matches everything.

Everything, or the ServerName defined globally?

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


RE: [users@httpd] Special configuration for requests that do not match any particular virtual host? Apache 2.2

Posted by Geoff Millikan <gm...@t1shopper.com>.
Poop.  It's a simple oversight.  Sorry everyone.  Tom Evans example works just fine.  The example from the original post would have
worked with the addition of a *ServerName*.  Without the ServerName, the vhost entry matches everything.

#This doesn't work
<VirtualHost *:80>
  RewriteEngine On
  RewriteRule .* http://www.mydomain.com%{REQUEST_URI} [L,R=301]
  ErrorLog /var/log/httpd/error_log
  CustomLog /var/log/httpd/access_log combined
</VirtualHost>

#This works great
<VirtualHost *:80>
  ServerName localhost-monkey-whatever-you-want-just-put-something-here
  RewriteEngine On
  RewriteRule .* http://www.mydomain.com%{REQUEST_URI} [L,R=301]
  ErrorLog /var/log/httpd/error_log
  CustomLog /var/log/httpd/access_log combined
</VirtualHost>

Again my apologies for filling your inboxes.  Beer is on me next time.


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


RE: [users@httpd] Special configuration for requests that do not match any particular virtual host? Apache 2.2

Posted by Geoff Millikan <gm...@t1shopper.com>.
> You misunderstood what Eric said. The first vhost absolutely can be
> used to redirect requests to another vhost. 
> I don't think I can make it any clearer than that - hope that helps.

Wow, thank you!  And just for kicks, look back at the original post - you can see the configuration you proposed is exactly what we
attempted.  But it didn't work. 
 
When we went to http://www.foo.com/ we expected the second vhost entry to pick it up because of the hostname match. But it didn't.
Instead the first vhost entry picked it up and redirected http://www.foo.com/ right back to http://www.foo.com/ putting us in an
infinite loop.

It shouldn't happen that way, but it is - and that's the original question, "Why isn't it working?"  I feel a bit embarrassed for
not being able to debug/figure it out and I'm hoping it's some simple oversight.  
 
http://www.gossamer-threads.com/lists/apache/users/399377



---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Special configuration for requests that do not match any particular virtual host? Apache 2.2

Posted by Tom Evans <te...@googlemail.com>.
On Thu, Jun 2, 2011 at 5:13 PM, Geoff Millikan <gm...@t1shopper.com> wrote:
>> Incorrect. The first vhost is ALWAYS used when no vhost with a
>> matching host name is found - it is the catch all vhost, by
>> definition.
>
> Yes, I totally agree.  But, the first vhost cannot be used to *redirect requests to another vhost.*  Per Eric Covener, "You can't
> make the catch-all vhost also be a reachable name-based vhost, with those rewrite rules.  Create an additional one solely for that
> purpose."
>
> If you're wanting to redirect all hostnames to parent domain name then the first vhost cannot be used for this purpose unless
> there's another solution the list hasn't thought of yet?
>

You misunderstood what Eric said. The first vhost absolutely can be
used to redirect requests to another vhost. This is the canonical way
to setup Apache to deal with misconfigured vhosts and redirect them to
a preferred vhost.

Eg, I have a server with a wildcard DNS enabled for *.foo.com. Most of
the resolvable DNS names aren't valid, and so should be redirected to
the www.foo.com vhost:

<VirtualHost *:80>
  ServerName localhost
  DocumentRoot /var/empty
  RewriteEngine On
  RewriteRule ^.* http://www.foo.com/ [L,R=302]
</VirtualHost>

<VirtualHost *:80>
  ServerName www.foo.com
  DocumentRoot /var/www/www.foo.com/htdocs
</VirtualHost>

<VirtualHost *:80>
  ServerName code.foo.com
  DocumentRoot /var/www/code.foo.com/htdocs
</VirtualHost>

Requests for http://not-valid.foo.com/whatever/ do not match a vhost,
and so are routed to the default vhost, which redirects them to
http://www.foo.com/

If you want to ALSO redirect from a specific hostname to another
specific vhost, then you must add another vhost for that specific
purpose, as Eric mentioned. If I had a site 'www-beta.foo.com', which
should now show 'www.foo.com', I would need to add an additional vhost
like so:

<VirtualHost *:80>
  ServerName www-beta.foo.com
  DocumentRoot /var/empty
  RewriteEngine On
  RewriteRule ^/(.*) http://www.foo.com/$1 [L,R=302]
</VirtualHost>


I don't think I can make it any clearer than that - hope that helps.

Cheers

Tom

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


RE: [users@httpd] Special configuration for requests that do not match any particular virtual host? Apache 2.2

Posted by Geoff Millikan <gm...@t1shopper.com>.
> Incorrect. The first vhost is ALWAYS used when no vhost with a
> matching host name is found - it is the catch all vhost, by
> definition.

Yes, I totally agree.  But, the first vhost cannot be used to *redirect requests to another vhost.*  Per Eric Covener, "You can't
make the catch-all vhost also be a reachable name-based vhost, with those rewrite rules.  Create an additional one solely for that
purpose."

If you're wanting to redirect all hostnames to parent domain name then the first vhost cannot be used for this purpose unless
there's another solution the list hasn't thought of yet? 



---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Special configuration for requests that do not match any particular virtual host? Apache 2.2

Posted by Tom Evans <te...@googlemail.com>.
On Thu, Jun 2, 2011 at 2:40 PM, Geoff Millikan <gm...@t1shopper.com> wrote:
> In order to have a "catch all" vhost that redirects all hostnames to another vhost we must capture everything with a ServerAlias.
> There's no other way.

Incorrect. The first vhost is ALWAYS used when no vhost with a
matching host name is found - it is the catch all vhost, by
definition.

Cheers

Tom

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


RE: [users@httpd] Special configuration for requests that do not match any particular virtual host? Apache 2.2

Posted by Geoff Millikan <gm...@t1shopper.com>.
> Not sure what you mean by crash...  

If I put "ServerAlias *" into httpd.conf and try to restart Apache, it will not start.  There's no error log as to why it will not
start.

> The first-listed vhost in a set of namevirtualhosts is the default.  

Agreed.  However it was said:

> You can't make the catch-all vhost also be a reachable name-based 
> vhost, with those rewrite rules.  Create an addl one solely 
> for that purpose.

In order to have a "catch all" vhost that redirects all hostnames to another vhost we must capture everything with a ServerAlias.
There's no other way.

Why is this needed?  As you know, Google will consider delisting you if you have two domains serving up the exact same content.
They consider it spamming the 'net.  

It's easy for this to happen accidentally - for us we created an A Record for performance.mydomain.com and pointed it to our
production web host IP address for some testing.  Google somehow found it and reindexed our whole site on that domain name.
Essentially Google had two copies of our site in the search results. Ugh.

Upon further inspection, we found there were other A Records which were showing duplicate content because of wildcards in place like
*.mycompany.com or just because we forgot to remove them.  With several hundred domain names, and a httpd.conf file several thousand
lines long, it's easy to lose track.

In other words, the "catch all" vhost is needed when an unknown number of hostnames are pointing at a server and it's desired that
they all resolve successfully yet redirect to the proper domain name so there's no duplicate content issues.


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Special configuration for requests that do not match any particular virtual host? Apache 2.2

Posted by Eric Covener <co...@gmail.com>.
> Ah ha! The issue was that doing "ServerAlias *" crashes Apache with no error log. ServerAlias apparently needs more than just a
> single wildcard character.  Putting the below <VirtualHost> entry after the last <VirtualHost> works great!  Sweet.

Not sure what you mean by crash, but this is unnecessary.  The
first-listed vhost in a set of namevirtualhosts is the default.  You
don't need to try to capture everything with a serveralias.

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


RE: [users@httpd] Special configuration for requests that do not match any particular virtual host? Apache 2.2

Posted by Geoff Millikan <gm...@t1shopper.com>.
> Eric C: You can't make the catch-all vhost also be a reachable name-based 
> vhost, with those rewrite rules.  Create an additional one 
> solely for that purpose.

> Jeroen G: Get rid of all the rewrite junk and just set a dummy servername; 
> this will catch ALL undefined hostnames.
> Then Redirect / to the correct vhost.

Ah ha! The issue was that doing "ServerAlias *" crashes Apache with no error log. ServerAlias apparently needs more than just a
single wildcard character.  Putting the below <VirtualHost> entry after the last <VirtualHost> works great!  Sweet.

<VirtualHost *:80>
      ServerName     my-catch-all-dummy-domain.com
      ServerAlias    *.com *.net *.org *.co *.mobi *.info *.me *.us *.biz *.tv *.ws
      RewriteEngine  On
      RewriteRule    .* http://www.mydomain.com%{REQUEST_URI} [L,R=301]
      ErrorLog       /var/log/httpd/error_log
      CustomLog      /var/log/httpd/access_log combined
</VirtualHost>

Now I cannot do the same thing for the 443 virtual host section - adding the below <VirtualHost> section crashes Apache with the
below strange error:

[Thu Jun 02 04:55:13 2011] [error] Illegal attempt to re-initialise SSL for server (theoretically shouldn't happen!)

<VirtualHost *:443>
      ServerName     my-catch-all-dummy-domain-SSL.com
      ServerAlias    *.com *.net *.org *.co *.mobi *.info *.me *.us *.biz *.tv *.ws
      RewriteEngine  On
      RewriteRule    .* https://www.mydomain.com%{REQUEST_URI} [L,R=301]
      ErrorLog       /var/log/httpd/error_log
      CustomLog      /var/log/httpd/access_log combined
</VirtualHost>


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


RE: [users@httpd] Special configuration for requests that do not match any particular virtual host? Apache 2.2

Posted by Geoff Millikan <gm...@t1shopper.com>.
> Get rid of all the rewrite junk and just set a dummy servername; this 
> will catch ALL undefined hostnames.
> Then Redirect / to the correct vhost.

Yep, we tried something like this (see below) and it crashed Apache even though the syntax is correct.

<VirtualHost *:80>
      #virtual host entry #1
</VirtualHost>

<VirtualHost *:80>
      #virtual host entry #2
</VirtualHost>

<VirtualHost *:80>
	#very last virtual host entry #934
	ServerName     t1shopper-catch-all.com
	ServerAlias    *
	RewriteEngine On
	RewriteRule 	.* http://www.t1shopper.com%{REQUEST_URI} [L,R=301]
</VirtualHost>


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Special configuration for requests that do not match any particular virtual host? Apache 2.2

Posted by Jeroen Geilman <je...@adaptr.nl>.
On 06/02/2011 01:05 AM, Geoff Millikan wrote:
> I want to make a catch-all virtual host (like the manual mentions below) which redirects any errant hostnames like
> http://oopsie.mydomain.com/ to our main hostname at http://www.mydomain.com/   But the below example doesn't work - I'm getting an
> infinite redirect from http://www.mydomain.com/ right back to http://www.mydomain.com/
>
> What am I missing?
>
> #First virtual host entry
> <VirtualHost *:80>
> 	RewriteEngine On
> 	RewriteRule 	.* http://www.mydomain.com%{REQUEST_URI} [L,R=301]
> 	ErrorLog 	/var/log/httpd/error_log
> 	CustomLog	/var/log/httpd/access_log combined
> </VirtualHost>

NO.

nonononono.

Get rid of all the rewrite junk and just set a dummy servername; this 
will catch ALL undefined hostnames.

Then Redirect / to the correct vhost.


-- 
J.


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Special configuration for requests that do not match any particular virtual host? Apache 2.2

Posted by Eric Covener <co...@gmail.com>.
On Wed, Jun 1, 2011 at 10:02 PM, Geoff Millikan <gm...@t1shopper.com> wrote:
>>> default server www.t1shopper.com (/etc/httpd/conf/httpd.conf:663)
>>> port 80 namevhost www.t1shopper.com (/etc/httpd/conf/httpd.conf:663)
>>
>>Is this the host that loops?
>
> Yes.  When I uncomment the first <VirtualHost> entry below, the infinite loop happens on the second <VirtualHost> entry but then
> again, that's the only domain we tested.

You can't make the catch-all vhost also be a reachable name-based
vhost, with those rewrite rules.  Create an addl one solely for that
purpose.

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


RE: [users@httpd] Special configuration for requests that do not match any particular virtual host? Apache 2.2

Posted by Geoff Millikan <gm...@t1shopper.com>.
>> default server www.t1shopper.com (/etc/httpd/conf/httpd.conf:663)
>> port 80 namevhost www.t1shopper.com (/etc/httpd/conf/httpd.conf:663)
>
>Is this the host that loops?

Yes.  When I uncomment the first <VirtualHost> entry below, the infinite loop happens on the second <VirtualHost> entry but then
again, that's the only domain we tested.

#First virtual host entry
#<VirtualHost *:80>
#	RewriteEngine On
#	RewriteRule 	.* http://www.t1shopper.com%{REQUEST_URI} [L,R=301]
#	ErrorLog 	/var/log/httpd/error_log
#	CustomLog	/var/log/httpd/access_log combined
#</VirtualHost>

<VirtualHost *:80>
   ServerName www.t1shopper.com
   DocumentRoot   /home/.../www
   <snip>
      


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Special configuration for requests that do not match any particular virtual host? Apache 2.2

Posted by Eric Covener <co...@gmail.com>.
>   default server www.t1shopper.com (/etc/httpd/conf/httpd.conf:663)
>   port 80 namevhost www.t1shopper.com (/etc/httpd/conf/httpd.conf:663)

Is this the host that loops?

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


RE: [users@httpd] Special configuration for requests that do not match any particular virtual host? Apache 2.2

Posted by Geoff Millikan <gm...@t1shopper.com>.
>Looks fine -- apachectl/apache2ctl/httpd -S output?

$ /usr/sbin/httpd -S
VirtualHost configuration:
wildcard NameVirtualHosts and _default_ servers:
*:443  is a NameVirtualHost
   default server www.t1shopper.com (/etc/httpd/conf/httpd.conf:1399)
   port 443 namevhost www.t1shopper.com (/etc/httpd/conf/httpd.conf:1399)
   port 443 namevhost static.t1shopper.com (/etc/httpd/conf/httpd.conf:1647)
   <snip>
   port 443 namevhost t1shopper.com (/etc/httpd/conf/httpd.conf:1713)
   port 443 namevhost wireless-t1.com (/etc/httpd/conf/httpd.conf:1797)
   <snip>
   port 443 namevhost t3shopper.com (/etc/httpd/conf/httpd.conf:1888)
*:80   is a NameVirtualHost
   default server www.t1shopper.com (/etc/httpd/conf/httpd.conf:663)
   port 80 namevhost www.t1shopper.com (/etc/httpd/conf/httpd.conf:663)
   port 80 namevhost a.static.t1shopper.com (/etc/httpd/conf/httpd.conf:978)
   <snip>
   port 80 namevhost t1shopper.com (/etc/httpd/conf/httpd.conf:1072)
   port 80 namevhost wireless-t1.com (/etc/httpd/conf/httpd.conf:1157)
   port 80 namevhost t1carrier.com (/etc/httpd/conf/httpd.conf:1170)
   <snip>
   port 80 namevhost t3shopper.com (/etc/httpd/conf/httpd.conf:1240)
   port 80 namevhost vpnshopper.com (/etc/httpd/conf/httpd.conf:1255)
Syntax OK


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Special configuration for requests that do not match any particular virtual host? Apache 2.2

Posted by Eric Covener <co...@gmail.com>.
On Wed, Jun 1, 2011 at 8:43 PM, Geoff Millikan <gm...@t1shopper.com> wrote:
>> missing NameVirtualHost *:80?  That would be the easiest way to get
>> sent back to the 1st vhost after the redirect.
>
> Eric, we've got that already but I'm hoping it's some simple oversight like that which is causing this.
>
> NameVirtualHost *:80
> Listen 80
> NameVirtualHost *:443
> Listen 443

Looks fine -- apachectl/apache2ctl/httpd -S output?



-- 
Eric Covener
covener@gmail.com

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


RE: [users@httpd] Special configuration for requests that do not match any particular virtual host? Apache 2.2

Posted by Geoff Millikan <gm...@t1shopper.com>.
> missing NameVirtualHost *:80?  That would be the easiest way to get
> sent back to the 1st vhost after the redirect.

Eric, we've got that already but I'm hoping it's some simple oversight like that which is causing this.

NameVirtualHost *:80
Listen 80
NameVirtualHost *:443
Listen 443




---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Special configuration for requests that do not match any particular virtual host? Apache 2.2

Posted by Eric Covener <co...@gmail.com>.
On Wed, Jun 1, 2011 at 7:05 PM, Geoff Millikan <gm...@t1shopper.com> wrote:
> I want to make a catch-all virtual host (like the manual mentions below) which redirects any errant hostnames like
> http://oopsie.mydomain.com/ to our main hostname at http://www.mydomain.com/   But the below example doesn't work - I'm getting an
> infinite redirect from http://www.mydomain.com/ right back to http://www.mydomain.com/

missing NameVirtualHost *:80?  That would be the easiest way to get
sent back to the 1st vhost after the redirect.

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


RE: [users@httpd] Special configuration for requests that do not match any particular virtual host? Apache 2.2

Posted by Geoff Millikan <gm...@t1shopper.com>.
> Actually on second thought, the rewrite rule in the first host 
> should be like this to avoid loop:
>       
>      RewriteEngine On
>      RewriteCond %{HTTP_HOST} !^www\.mydomain\.com [OR]
>      RewriteCond %{HTTP_HOST} !^mydomain\.com
>      RewriteRule     .* http://www.mydomain.com%{REQUEST_URI} [L,R=301]

Per manual excerpted below, the first <VirtualHost> section should only be used when the hostname being requested isn't listed
anywhere else in a ServerName or ServerAlias, right?!  So these RewriteCond shouldn't be needed!  Right?

I'd use exclusion RewriteCond but since we have other domain names on the server like www.MyPersonalWebsite.com and
www.OurOldCompanyName.com etc we'd have to write rule for each domain.  Messy. 

Thanks,

Geoff

"Now when a request arrives, the server will first check if it is using an IP address that matches the NameVirtualHost. If it is,
then it will look at each <VirtualHost> section with a matching IP address and try to find one where the ServerName or ServerAlias
matches the requested hostname. If it finds one, then it uses the configuration for that server. If no matching virtual host is
found, then the first listed virtual host that matches the IP address will be used." 

http://httpd.apache.org/docs/current/vhosts/name-based.html



---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Special configuration for requests that do not match any particular virtual host? Apache 2.2

Posted by Igor Cicimov <ic...@gmail.com>.
Actually on second thought, the rewrite rule in the first host should be
like this to avoid loop:

       RewriteEngine On
       RewriteCond %{HTTP_HOST} !^www\.mydomain\.com [OR]
       RewriteCond %{HTTP_HOST} !^mydomain\.com
       RewriteRule     .* http://www.mydomain.com%{REQUEST_URI} [L,R=301]

Cheers,
Igor

On Thu, Jun 2, 2011 at 9:59 AM, Igor Cicimov <ic...@gmail.com> wrote:

> Change the order of the hosts since the first one matches first.
>
> Igor
>
>
> On Thu, Jun 2, 2011 at 9:48 AM, Geoff Millikan <gm...@t1shopper.com>wrote:
>
>> > Try making the first one _default_ host
>> > <VirtualHost _default_:80>
>>
>> Thanks but since we're doing name-based virtual hosting I don't believe
>> that will apply to us because the manual says the _default_
>> setting only applies to IP virtual hosting but let me know if you have
>> thoughts otherwise!
>>
>> "The string _default_ is used only with IP virtual hosting to catch
>> unmatched IP addresses." -
>> http://httpd.apache.org/docs/current/mod/core.html#virtualhost
>>
>>
>>
>>
>> ---------------------------------------------------------------------
>> The official User-To-User support forum of the Apache HTTP Server Project.
>> See <URL:http://httpd.apache.org/userslist.html> for more info.
>> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
>>   "   from the digest: users-digest-unsubscribe@httpd.apache.org
>> For additional commands, e-mail: users-help@httpd.apache.org
>>
>>
>

Re: [users@httpd] Special configuration for requests that do not match any particular virtual host? Apache 2.2

Posted by Igor Cicimov <ic...@gmail.com>.
Change the order of the hosts since the first one matches first.

Igor

On Thu, Jun 2, 2011 at 9:48 AM, Geoff Millikan <gm...@t1shopper.com>wrote:

> > Try making the first one _default_ host
> > <VirtualHost _default_:80>
>
> Thanks but since we're doing name-based virtual hosting I don't believe
> that will apply to us because the manual says the _default_
> setting only applies to IP virtual hosting but let me know if you have
> thoughts otherwise!
>
> "The string _default_ is used only with IP virtual hosting to catch
> unmatched IP addresses." -
> http://httpd.apache.org/docs/current/mod/core.html#virtualhost
>
>
>
>
> ---------------------------------------------------------------------
> The official User-To-User support forum of the Apache HTTP Server Project.
> See <URL:http://httpd.apache.org/userslist.html> for more info.
> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
>   "   from the digest: users-digest-unsubscribe@httpd.apache.org
> For additional commands, e-mail: users-help@httpd.apache.org
>
>

RE: [users@httpd] Special configuration for requests that do not match any particular virtual host? Apache 2.2

Posted by Geoff Millikan <gm...@t1shopper.com>.
> Try making the first one _default_ host 
> <VirtualHost _default_:80>

Thanks but since we're doing name-based virtual hosting I don't believe that will apply to us because the manual says the _default_
setting only applies to IP virtual hosting but let me know if you have thoughts otherwise!

"The string _default_ is used only with IP virtual hosting to catch unmatched IP addresses." -
http://httpd.apache.org/docs/current/mod/core.html#virtualhost




---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Special configuration for requests that do not match any particular virtual host? Apache 2.2

Posted by Igor Cicimov <ic...@gmail.com>.
Try making the first one _default_ host

<VirtualHost _default_:80>

Igor



On Thu, Jun 2, 2011 at 9:05 AM, Geoff Millikan <gm...@t1shopper.com>wrote:

> I want to make a catch-all virtual host (like the manual mentions below)
> which redirects any errant hostnames like
> http://oopsie.mydomain.com/ to our main hostname at
> http://www.mydomain.com/   But the below example doesn't work - I'm
> getting an
> infinite redirect from http://www.mydomain.com/ right back to
> http://www.mydomain.com/
>
> What am I missing?
>
> #First virtual host entry
> <VirtualHost *:80>
>        RewriteEngine On
>        RewriteRule     .* http://www.mydomain.com%{REQUEST_URI} [L,R=301]
>        ErrorLog        /var/log/httpd/error_log
>        CustomLog       /var/log/httpd/access_log combined
> </VirtualHost>
>
> #Second virtual host entry
> <VirtualHost *:80>
>        ServerName      www.mydomain.com
>        DocumentRoot   /home/mydomain/www
>        <Directory /home/mydomain/www>
>                Options -ExecCGI +FollowSymLinks +IncludesNOEXEC -Indexes
> -MultiViews +Includes
>                AllowOverride None
>        </Directory>
>        ErrorLog        /var/log/httpd/error_log
>        CustomLog       /var/log/httpd/access_log combined
> </VirtualHost>
>
> http://httpd.apache.org/docs/2.2/vhosts/name-based.html - "If you would
> like to have a special configuration for requests that do
> not match any particular virtual host, simply put that configuration in a
> <VirtualHost> container and list it first in the
> configuration file."
>
>
> ---------------------------------------------------------------------
> The official User-To-User support forum of the Apache HTTP Server Project.
> See <URL:http://httpd.apache.org/userslist.html> for more info.
> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
>   "   from the digest: users-digest-unsubscribe@httpd.apache.org
> For additional commands, e-mail: users-help@httpd.apache.org
>
>