Home > apache > Using apache’s RedirectMatch instead of ServerAlias to avoid content duplication

Using apache’s RedirectMatch instead of ServerAlias to avoid content duplication

Most web sites I do have many domains but want all those domains to point to the “main domain” www.domain.com. My first solution was to put Apaches’s directive ServerAlias in the site’s virtual host configuration. This lead to content duplication since domain.com and domain.net and www.domain.com are two different web sites for the rest of the world. To avoid this problem the only solution I’ve found was to create two different virtual hosts and set Apache’s Redirect directive. The first VirtualHost will hold all the domains aliases and redirect permanently (301) to the “main domain”

<VirtualHost ip_address:80>
    ServerName domain.com
    ServerAlias domain.net
    ServerAlias domain.biz
    RedirectMatch permanent /(.*) http://www.domain.com/$1
</VirtualHost>
 
<VirtualHost ip_address:80>
    ServerName www.domain.com
    etc...
</VirtualHost>
http://blog.melimato.com/wp-content/plugins/sociofluid/images/digg_24.png http://blog.melimato.com/wp-content/plugins/sociofluid/images/reddit_24.png http://blog.melimato.com/wp-content/plugins/sociofluid/images/stumbleupon_24.png http://blog.melimato.com/wp-content/plugins/sociofluid/images/delicious_24.png http://blog.melimato.com/wp-content/plugins/sociofluid/images/technorati_24.png http://blog.melimato.com/wp-content/plugins/sociofluid/images/google_24.png http://blog.melimato.com/wp-content/plugins/sociofluid/images/myspace_24.png http://blog.melimato.com/wp-content/plugins/sociofluid/images/facebook_24.png http://blog.melimato.com/wp-content/plugins/sociofluid/images/yahoobuzz_24.png http://blog.melimato.com/wp-content/plugins/sociofluid/images/twitter_24.png http://blog.melimato.com/wp-content/plugins/sociofluid/images/meneame_24.png
Categories: apache Tags: ,
  1. buy_vigrxplus
    July 16th, 2009 at 00:14 | #1

    Pretty cool post. I just stumbled upon your blog and wanted to say
    that I have really liked reading your blog posts. Anyway
    I’ll be subscribing to your blog and I hope you post again soon!

  2. Patrick
    October 23rd, 2009 at 15:43 | #2

    This is pretty cool, but how do you handle the same for the https:// domain.

    I did try and and it looks not working. No redirection …

    • pablo
      October 23rd, 2009 at 16:09 | #3

      https needs 1 IP per virtual host. So you would have to create 2 virtual hosts listening on 2 different IPs and use the same syntax to redirect the one without www to the one with it.

  1. No trackbacks yet.

Comment moderation is enabled. Your comment may take some time to appear.

Additional comments powered by BackType