httpd-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tom Evans <tevans...@googlemail.com>
Subject Re: [users@httpd] 'redirect' to a single domain name
Date Fri, 16 Mar 2012 12:38:48 GMT
On Fri, Mar 16, 2012 at 12:25 PM, Lester Caine <lester@lsces.co.uk> wrote:
> OK ... I've always set the server up so that both xxx.co.uk and
> www.xxx.co.uk are processed, but the 'quality police' are now flagging this
> as wrong, and saying that one or the other should be 'returned' by the site.
> Since some sites also have xxx.com or other options this does make sense,
> the question is how?
>
> I'm already using rewrite to keep the wingers happy on 'tidy url's' and that
> works well, and if I am readying things correctly 'Redirect' should handle
> the domain? But it does not seem to work. I assume that this needs to be
> handled inside the <VirtualHost> for it to correctly map what is listed in
> the ServerAlias to match the ServerName entry?
>
> What IS the politically correct way of handling this?
>

I know of two ways :)

1) Use two vhosts and a redirect:

<VirtualHost *>
  ServerName www.canonicalsitename.com
</VirtualHost>

<VirtualHost *>
  ServerName analias.canonicalsitename.com
  ServerAlias *.canonicalsitename.com
  Redirect / http://www.canoncialsitename.com/
</VirtualHost>

2) Use one vhost and a rewrite rule:

<VirtualHost *>
  ServerName www.canonicalsitename.com
  ServerName analias.canonicalsitename.com
  ServerAlias *.canonicalsitename.com
  RewriteCond %{HTTP_HOST} !^www.canonicalsitename.com$
  RewriteRule ^/(.*) http://www.canonicalsitename/$1 [R=301,L]
</VirtualHost>

Tapped all that out, and THEN remembered that this is a FAQ:

http://httpd.apache.org/docs/2.2/rewrite/remapping.html#canonicalhost

Cheers

Tom

PS: the same Lester Caine who posts on the register boards?

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


Mime
View raw message