Multiple domains, one IP; Rewrite all to www.charlie.com

Using a single web hosting account to host multiple sites

Multiple domains, one IP; Rewrite all to www.charlie.com

Postby Chip » Sun Apr 19, 2009 12:43 am

Hi,
Three domains all point to one IP address on Apache 2.2.X. The goal is to have any page requested from (not the actual names) alpha.com (or www.alpha.com), bravo.com (or www.bravo.com), or charlie.com, be served as pages from www.charlie.com because www.charlie.com is the parent company's name. The other domains are perhaps "aliases" (domains named for company subdivisions--is "alias" the right term?). Does it probably serve the company best to serve all page requests as main company name domain (www.charlie.com). Comment on this approach?

The problem I've run into is I am unsure of my RewriteCond and RewriteRule construction. We're having sporadic problems with page requests on bravo.com; to isolate where the problem lies, I need feedback on this part of my .htaccess. Here is the code:

Code: Select all
Options +FollowSymlinks +Includes
RewriteEngine on
RewriteBase /

RewriteCond %{HTTP_HOST} www.alpha\.com [NC]
RewriteRule ^(.*)$ http://www.charlie.com/$1 [R=301]

RewriteCond %{HTTP_HOST} ^alpha\.com [NC]
RewriteRule ^(.*)$ http://www.charlie.com/$1 [R=301]

RewriteCond %{HTTP_HOST} www.bravo\.com [NC]
RewriteRule ^(.*)$ http://www.charlie.com/$1 [R=301]

RewriteCond %{HTTP_HOST} ^bravo\.com [NC]
RewriteRule ^(.*)$ http://www.charlie.com/$1 [R=301]

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

RewriteCond %{THE_REQUEST} ^[^/]*/index\.html [NC]
RewriteRule . / [R=301,L]


This is what I cobbled together from research here and other places. Is there a more elegant solution? Do I need to identify alpha/bravo/charlie individually in this way or can same result be achieved using wildcards? Is there anything here that would cause requests on bravo.com or www.bravo.com to return error pages (domain not found or is having problems)?

Thank you kindly for your review.
Chip
 
Posts: 2
Joined: Sun Apr 19, 2009 12:01 am

Postby richardk » Sun Apr 19, 2009 6:04 am

You can check that the HTTP_HOST is not www.example.com
Code: Select all
Options +FollowSymlinks +Includes

RewriteEngine On

# If it's not www.example.com...
RewriteCond %{HTTP_HOST} !^www\.example\.com [NC]
# ...redirect to www.example.com
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]

# Remove all "index.html"s.
RewriteCond %{THE_REQUEST} \ /(.+/)?index\.html(\?.*)?\  [NC]
RewriteRule ^(.+/)?index\.html$ /%1 [R=301,L]


I don't think the mod_rewrite is the cause of the bravo.com problems.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Thank you!

Postby Chip » Sun Apr 19, 2009 4:07 pm

Hi, richardk.

I appreciate your expertise; thank you for sharing it. Your proposal is cleaner, with fewer lines of code and fewer possibilities for error.
Chip
 
Posts: 2
Joined: Sun Apr 19, 2009 12:01 am

Postby Ned » Sat May 02, 2009 11:41 am

Thanks Richard this helped me out also.
Ned
 
Posts: 1
Joined: Sat May 02, 2009 11:40 am


Return to Domain Handling

Who is online

Users browsing this forum: No registered users and 14 guests

cron