httpd-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jeroen Geilman <jer...@adaptr.nl>
Subject Re: [users@httpd] cleanest/fastest way of redirecting aliases to canonical server names
Date Sat, 29 Jan 2011 11:42:59 GMT
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


Mime
View raw message