Page 1 of 1

Redirect .htaccess to 'www' sub-domain

Posted: Fri Apr 24, 2009 8:11 am
by alex.barylski
I have the following .htacess borrowed from Zend Framework:

Code: Select all

RewriteEngine On
 
# THESE lines don't work???
#RewriteCond %{HTTP_HOST} ^www.cliquedevel.com [nc]
#RewriteRule ^(.*)$ http://cliquedevel.com/$1 [r=301,nc]
 
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
 
RewriteRule ^.*$ - [NC,L]
 
RewriteRule ^.*$ index.php [NC,L]
We have a wildcard sub-domain setup through our ISP so accessing
subdomain1.domain.com
subdomain2.domain.com
Will be common place. However I would still like to redirect (301?) an empty sub-domain to 'www' by default.

Basically only when there is no sub-domain should the .htaccess redirect (permenently or temp?) to http://www.domain.com

Can someone show me what I would add to the above .htaccess and explain how it works? I have searched Google and found articles but all of them do this redirect in PHP and I would prefer to have this done in .htaccess

Cheers,
Alex