You are viewing a plain text version of this content. The canonical link for it is here.
Posted to docs@httpd.apache.org by Vincent Bray <no...@gmail.com> on 2007/01/30 10:01:22 UTC

Re: [Httpd Wiki] Update of "Recipes/CanonicalHostNames" by slive

Hi Joshua,

On 30/01/07, Apache Wiki <wi...@apache.org> wrote:
> The comment on the change is:
> The old example would not canonicalize non-listed hostnames.
>
> ------------------------------------------------------------------------------
>   NameVirtualHost *:80
>
>   <VirtualHost *:80>
> +   # The first-listed <VirtualHost> is the default host that catches all the
> +   # names specified in its ServerName/ServerAlias, plus all the names
> +   # that are not listed in any other <VirtualHost>, and redirects
> +   # them to the canonical <VirtualHost> below.
> +   ServerName www.example.net
> +   ServerAlias example.com
> +   Redirect permanent / http://www.example.com/
> + </VirtualHost>
> +
> + <VirtualHost *:80>
>     # Canonical host
>     ServerName www.example.com
>     DocumentRoot /usr/local/apache/htdocs
>   </VirtualHost>
>
> - <VirtualHost *:80>
> -   # Non-canonical names for the above vhost
> -   ServerName www.example.net
> -   ServerAlias example.com
> -   Redirect permanent / http://www.example.com/
> - </VirtualHost>
>   }}}
>
>   == Using mod_rewrite ==
>

The change I made was a result of a user in #apache getting confused
about the default vhost part. He already had a default vhost (debian
config) and didn't want to edit it to redirect non-canonical hostnames
for a single vhost. This makes sense when you apply this config
pattern to multiple hostname combinations. Here's the conversation, up
to you if you want to remove the default vhost comment.

*	Luke (n=Luke@74-132-214-24.dhcp.insightbb.com) has joined #apache
<Luke>	i'm trying to find a rewrite rule that will forward from
www.domain.com to domain.com. what would I call that so I can more
effectively search?
<noodl>	Luke: you don't need mod_rewrite for that, just Redirect in a
separate vhost. for a search, i'd suggest 'canonical hostname'
<Luke>	i'm not sure how to do that. searching canonical hostname is
actually how I found how to do mod_rewrite
<noodl>	Luke: http://wiki.apache.org/httpd/Recipes/CanonicalHostNames
<Luke>	i found how to remove www (i had to use quotes)
<Luke>	why is it not good to use mod_rewrite in this case?
<noodl>	granny
<fajita>	Granny Weatherwax tells us the most important thing about
magic is when _not_ to use it.  The same is true of mod_rewrite.
<noodl>	it's just slower and unnecessary
<Luke>	much easier though
<noodl>	really? i don't think so.
<noodl>	RedirectPermanent is pretty straight-forward imho.
<Luke>	i dont just have one vhost though
<noodl>	only you need rewrite for this is when you cant edit the main
config and need to use .htaccess
<Luke>	yea
<noodl>	doesn't make any difference. just add another vhost.
<noodl>	(that wiki page is misleading talking about the first one
being the default, it's kinda irrelevant to the example)
<Luke>	looks here like it goes in the default vhost
<Luke>	ah
<Luke>	thats what was confusing me
<Luke>	so I just make a vhost for the www and use redirect?
<noodl>	yep
<noodl>	fixed the page
<Luke>	cool thaks
<Luke>	thats much better now


-- 
noodl

---------------------------------------------------------------------
To unsubscribe, e-mail: docs-unsubscribe@httpd.apache.org
For additional commands, e-mail: docs-help@httpd.apache.org


Re: [Httpd Wiki] Update of "Recipes/CanonicalHostNames" by slive

Posted by Joshua Slive <jo...@slive.ca>.
On 1/30/07, Vincent Bray <no...@gmail.com> wrote:

> The change I made was a result of a user in #apache getting confused
> about the default vhost part. He already had a default vhost (debian
> config) and didn't want to edit it to redirect non-canonical hostnames
> for a single vhost. This makes sense when you apply this config
> pattern to multiple hostname combinations. Here's the conversation, up
> to you if you want to remove the default vhost comment.

I've tried to clarify it.  But I think it is important to mention the
default host issue, because it should be considered a "best practice"
to canonicalize requests for this host.  Otherwise, requests coming in
using the IP address or other non-handled names wind up being dealt
with improperly.

Joshua.

---------------------------------------------------------------------
To unsubscribe, e-mail: docs-unsubscribe@httpd.apache.org
For additional commands, e-mail: docs-help@httpd.apache.org