You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Christoph Anton Mitterer <ca...@scientia.net> on 2011/01/29 02:38:54 UTC

[users@httpd] cleanest/fastest way of redirecting aliases to canonical server names

Hi.

I'm having a vhost, which is reachable via one canonical name, e.g.
example.org, and also via several aliases, e.g. www.example.org,
example.com, etc.

I want that whenever requests are made via one of the aliases, that
those are redirected to the canonical name.


IMHO there are about the following two ways:
1)
- one vhost, which has the canonical name as ServerName, and the aliases
as ServerAliases
- and also has some RewriteCond+RewriteRules, making a redirect to the
canonical address if HTTP_HOST is one of the aliases.


2)
- two vhosts, the first having only the canonical name as ServerName (no
ServerAlias)

- the second, having the aliases as ServerName/ServerAliases
- and also doing a Redirect / http://example.org



Can (2) be handled with more performance by Apache than (1) (as it
doesn't have to evaluate the RewriteConds and the regexps every time?

At least (1) seems to be cleaner readable to me (from a config file
point of view)


Cheers,
Chris.

Re: [users@httpd] cleanest/fastest way of redirecting aliases to canonical server names

Posted by Jeroen Geilman <je...@adaptr.nl>.
On 1/29/11 12:49 PM, Joost de Heer wrote:
>
>> 2)
>> - two vhosts, the first having only the canonical name as ServerName (no
>> ServerAlias)
>
> 3)
> Two vhosts, the first having a bogus servername (e.g. 'redirecthost'), 
> in which you do the redirection, and the second, which has the 
> canonical name.
>

What happens when he wants to use this mechanism for multiple sets of 
canonical names and aliases ?

-- 
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] cleanest/fastest way of redirecting aliases to canonical server names

Posted by Joost de Heer <jo...@sanguis.xs4all.nl>.
> 2)
> - two vhosts, the first having only the canonical name as ServerName (no
> ServerAlias)

3)
Two vhosts, the first having a bogus servername (e.g. 'redirecthost'), in which 
you do the redirection, and the second, which has the canonical name.

If you use NVH and none of the hosts match, the first one is used. In this case 
you don't have to add a new hostname whenever you decide to add a new one 
(example.net).

Joost

---------------------------------------------------------------------
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] cleanest/fastest way of redirecting aliases to canonical server names

Posted by Matus UHLAR - fantomas <uh...@fantomas.sk>.
On 29.01.11 02:38, Christoph Anton Mitterer wrote:
> I'm having a vhost, which is reachable via one canonical name, e.g.
> example.org, and also via several aliases, e.g. www.example.org,
> example.com, etc.
> 
> I want that whenever requests are made via one of the aliases, that
> those are redirected to the canonical name.
> 
> 
> IMHO there are about the following two ways:
> 1)
> - one vhost, which has the canonical name as ServerName, and the aliases
> as ServerAliases
> - and also has some RewriteCond+RewriteRules, making a redirect to the
> canonical address if HTTP_HOST is one of the aliases.
> 
> 
> 2)
> - two vhosts, the first having only the canonical name as ServerName (no
> ServerAlias)
> 
> - the second, having the aliases as ServerName/ServerAliases
> - and also doing a Redirect / http://example.org

3) use special modules as mod_redirtoservname (debian) or
mod_common_redirect (gentoo) that do this.
(unfortunately, the latter bugs on ssl sites)

-- 
Matus UHLAR - fantomas, uhlar@fantomas.sk ; http://www.fantomas.sk/
Warning: I wish NOT to receive e-mail advertising to this address.
Varovanie: na tuto adresu chcem NEDOSTAVAT akukolvek reklamnu postu.
Despite the cost of living, have you noticed how popular it remains? 

---------------------------------------------------------------------
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] cleanest/fastest way of redirecting aliases to canonical server names

Posted by Jeroen Geilman <je...@adaptr.nl>.
On 1/29/11 2:38 AM, Christoph Anton Mitterer wrote:
> Hi.
>
> I'm having a vhost, which is reachable via one canonical name, e.g.
> example.org, and also via several aliases, e.g. www.example.org,
> example.com, etc.
>
> I want that whenever requests are made via one of the aliases, that
> those are redirected to the canonical name.
>
>
> IMHO there are about the following two ways:
> 1)
> - one vhost, which has the canonical name as ServerName, and the aliases
> as ServerAliases
> - and also has some RewriteCond+RewriteRules, making a redirect to the
> canonical address if HTTP_HOST is one of the aliases.

This is generally the right way only if you have a hosted account, i.e. 
you only have access to one vhost period.
If you have control over httpd.conf, avoid rewriting as much as possible.

> 2)
> - two vhosts, the first having only the canonical name as ServerName (no
> ServerAlias)
>
> - the second, having the aliases as ServerName/ServerAliases
> - and also doing a Redirect / http://example.org

That would be my choice.

> Can (2) be handled with more performance by Apache than (1) (as it
> doesn't have to evaluate the RewriteConds and the regexps every time?

That's quite irrelevant, as the redirect requires an entire network 
round-trip, not to mention any client-side processing.

Rewrite performance is insignificant compared to the overhead of a 
network round-trip.

However, the Redirect forces the network round-trip regardless, so it's 
a moot point.

> At least (1) seems to be cleaner readable to me (from a config file
> point of view)
>

No, it's not cleaner at all. Using Rewrites funges your output and makes 
troubleshooting harder.


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