CoolComputing Logo
Coupons/Deals  ·  New Promo Codes/Coupons  · August 18, 2018

Apache Configuration for Domain Redirection for Unforeseen Sub-domains

Posted on Monday, May 16, 2011 @ 05:02:45 PM CDT by David Yee [] [read 2074 times]

 
Tips: Linux/Unix world
One of our websites all of a sudden had visitors through Google via it's name server subdomain of NS1. For instance, people come coming in through (for instance) ns1.Coolcomputing.com instead of www.coolcomputing.com for some reason. Of course, we don't want any sort of duplicate content/listing on search engine results, so what we need to do is to redirect those sub-domain names to the proper one (www). Here's how we did it via Apache to do a permanent 301 redirection (you need tje Apache rewrite module turned on)- example httpd.conf virtualhost configuration chunk below:

<VirtualHost 1.2.3.4>
ServerName ns1.coolcomputing.com
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} !^coolcomputing.com
RewriteRule ^(.*)$ http://www.coolcomputing.com/$1 [R=301,L]
</VirtualHost>


What I was pleasantly surprised with was that no DocumentRoot or logging directives or needed in a VirtualHost section.

Now I wish there's a cleaner way to do it, for instance a "catch-all" directive to 301 redirect all non "www." to www.coolcomputing.com.



Please rate this article or post a brief review of Apache Configuration for Domain Redirection for Unforeseen Sub-domains or comment on benchmark/performance, features, availability, price or anything else regarding Apache Configuration for Domain Redirection for Unforeseen Sub-domains. Thanks!

Apache Configuration For Domain Redirection For Unforeseen Sub Domains Rating: 2.0/5 (13 votes cast)

Your Name:
I have read and agreed to the Review Posting Agreement.
Review Title:
Comment/Review: