You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Igor Cicimov <ic...@gmail.com> on 2011/06/02 01:36:24 UTC

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

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
>
>

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