non www .htaccess redirect - ignore other subdomains.

Posted by qxxx on Stack Overflow See other posts from Stack Overflow or by qxxx
Published on 2010-04-12T09:50:23Z Indexed on 2010/04/12 9:53 UTC
Read the original article Hit count: 259

Filed under:
|
|
|

Hi,

I have a .htaccess redirect for "non www" like this:

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

it is working. But, i have also some subdomains other than www. If I call for example http://shop.example.com it redirects me to: http://www.shop.example.com

I dont want to write the subdomains into the .htaccess file, it should work automatically, just ignore anything else than www and '' like this:

if subdomain =='' -> redirect to www.HTTP_HOST....
elseif subdomain !='' && subdomain !='www' -> do nothing.

thanks!

© Stack Overflow or respective owner

Related posts about .htaccess

Related posts about mod-rewrite