homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

Domain name redirection via Apache VHOST config or via DNS mgmt tool?
How do I do it?

10+ Year Member

Msg#: 3997705 posted 2:08 pm on Sep 24, 2009 (gmt 0)

Hi there,

I have a tool called NIC tool which allows me to manage DNS settings. And I have a website called example.com which is currently accessible trough www.example.com, somesubdomain.example.com, test.example.com. All these (sub)domains point to the same ip address.

Now, I want all these domains to redirect to www.example.com. That is, when I type somesubdomain.example.com it should redirect to www.example.com and that is what the address bar should show.

How would I do this? Should this be done in the Apache VHOST config or can I accomplish this trouhh my DNS management tool?




WebmasterWorld Senior Member jdmorgan us a WebmasterWorld Top Contributor of All Time 10+ Year Member

Msg#: 3997705 posted 3:49 pm on Sep 24, 2009 (gmt 0)

If you have separate vHost containers for each of these domains and subdomains, put a mod_alias "RedirectPermanent" directive into each container, specifying that all requested URL-paths are to be 301-redirected to the canonical domain while retaining the requested URL-path (that is, keep the "page," just change the domain).

If all of these domains and subdomains resolve to the same vHost (i.e. if the ServerAlias specifies a wildcard subdomain), then use mod_rewrite to check %{HTTP_HOST} and 301-redirect to the canonical domain (again retaining the "page") if and only if the requested hostname is NOT exactly the canonical domain (or blank, to prevent an infinite loop in case you get an HTTP/1.0 request without a Host: header).

Example for use in httpd.conf, outside of any <Directory> container:

RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$
RewriteRule ^/(.*)$ http://www.example.com/$1 [R=301,L]


Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved