Domain www but sub no www

Using a single web hosting account to host multiple sites

Domain www but sub no www

Postby JohnnyK » Sat May 12, 2007 5:13 am

Hi again,

I have a domain I which I am using the following simple code.


Code: Select all
RewriteCond %{http_host} ^domain.com [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]


But I would like my subdomains to be rewritten without the www.

For example: www.sub.domain.com would be re written to sub.domain.com but domain.com would be re written to www.domain.com.

Any help appreciated.

John
JohnnyK
 
Posts: 5
Joined: Fri Apr 27, 2007 4:03 am

Postby richardk » Sat May 12, 2007 1:03 pm

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

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

RewriteCond %{HTTP_HOST} ^www\.(.+\.domain\.com)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby JohnnyK » Sat May 12, 2007 1:25 pm

Thanks again richardk!


Worked great!
JohnnyK
 
Posts: 5
Joined: Fri Apr 27, 2007 4:03 am


Return to Domain Handling

Who is online

Users browsing this forum: No registered users and 117 guests

cron