Multiple tld redirection

Using a single web hosting account to host multiple sites

Multiple tld redirection

Postby pwalters » Sun Nov 23, 2008 10:22 am

I am sure this is a very common practice, but I was wondering what the cleanest way to Rewrite the following setup is:

Here is the folder structure at root (/):

/static (static.domain.com currently resolves here)
/test-static (test-static.domain.com currently resolves here)
/test-www (test-www.domain.com currently resolves here)
/www (www.domain.com currently resolves here)

The current domains under control are .com, .info, .name, .net and .org

Rewrite Behavoir intended:

domain.* -> www.domain.com
static.domain.* -> static.domain.com (except static.domain.com -> static.domain.com)
test-static.domain.* -> test-static.domain.com (except test-static.domain.com -> test-static.domain.com)
test-www.domain.* -> test-static.domain.com (except test-www.domain.com -> test-www.domain.com)
www.domain.* -> www.domain.com (except www.domain.com -> www.domain.com)

For that matter, *.domain.* should resolve to *.domain.com with the exception to *.domain.com. I also intend to keep everything after the host the same.

Example a request to http://domain.org/test.html becomes http://www.domain.com/test.html
pwalters
 
Posts: 2
Joined: Sun Nov 23, 2008 9:34 am

Postby richardk » Sun Nov 23, 2008 10:41 am

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{HTTP_HOST} ^((.+\.)?example\.)(info|name|net|org)$ [NC]
RewriteRule .* http://%1com%{REQUEST_URI} [R=301,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby pwalters » Sun Feb 01, 2009 9:11 am

Richard,

This almost works perfectly, except the example of:

http://domain.org/test.html changing to http://domain.com/test.html instead of http://www.domain.com/test.html. All of the other subdomains redirect just fine. Is there a way to handle the case of the domain to hostname redirect by using the existing matching criteria?

e.g. keep all rules as is except if there is no "." before domain, it falls to the www.domain.com rule

Regards
pwalters
 
Posts: 2
Joined: Sun Nov 23, 2008 9:34 am

Postby richardk » Sun Feb 01, 2009 11:40 am

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond www.%{HTTP_HOST} ^(www\.example\.)(info|name|net|org|com)$ [NC,OR]
RewriteCond %{HTTP_HOST} ^((.+\.)?example\.)(info|name|net|org)$ [NC]
RewriteRule .* http://%1com%{REQUEST_URI} [R=301,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am


Return to Domain Handling

Who is online

Users browsing this forum: No registered users and 18 guests

cron