Redirecting nonwww requests to www for multiple tld's.

Using a single web hosting account to host multiple sites

Redirecting nonwww requests to www for multiple tld's.

Postby Moguai » Mon Oct 15, 2007 2:00 am

I own 6 domains, basically mydomain.com/net/org/info/us/ws; I'd like to have one rule read in the http_host value and redirect users to the www version of THAT domain without having to use the same rule for each tld.

The current rule I'm using is:
Code: Select all
rewritecond %{http_host} ^([a-zA-Z0-9]+\.com) [NC]
RewriteRule (.*) http://www.%1/$1 [R=301,L]
rewritecond %{http_host} ^([a-zA-Z0-9]+\.net) [NC]
RewriteRule (.*) http://www.%1/$1 [R=301,L]
rewritecond %{http_host} ^([a-zA-Z0-9]+\.org) [NC]
RewriteRule (.*) http://www.%1/$1 [R=301,L]
rewritecond %{http_host} ^([a-zA-Z0-9]+\.info) [NC]
RewriteRule (.*) http://www.%1/$1 [R=301,L]
rewritecond %{http_host} ^([a-zA-Z0-9]+\.us) [NC]
RewriteRule (.*) http://www.%1/$1 [R=301,L]
rewritecond %{http_host} ^([a-zA-Z0-9]+\.ws) [NC]
RewriteRule (.*) http://www.%1/$1 [R=301,L]


I'm in no way even proficient in mod_rewrite or regex; ideally i'd like one rule and i'm pretty sure it's possible, any help? I don't really understand the tags much, but I'm sure it'd be something like:
Code: Select all
rewritecond %{http_host} ^([a-zA-Z0-9])\.(com|net|org|info|us|ws) [NC]
RewriteRule (.*) http://www.%1/$1 [R=301,L]


But I'm not sure what the rewrite rule would be or anything like that...

PS, I'm looking for a .htaccess solution vs a httpd.conf solution.
Moguai
 
Posts: 2
Joined: Mon Oct 15, 2007 1:55 am

Postby richardk » Tue Oct 16, 2007 7:52 am

Close, try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{HTTP_HOST} ^([a-z0-9]\.(com|net|org|info|us|ws))$ [NC]
RewriteRule ^(.*)$ http://www.%1/$1 [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 24 guests

cron