IT.COM

.htaccess - Redirect sub-domains except www

Spaceship Spaceship
Watch
Hi,

I know how to redirect all subdomains using a .htaccess file, but how do I exclude www from redirected.

E.g. australia.music-chart.info -> redirects to Australia Music Chart | ITunes Music Chart Archive
japan.music-chart.info -> redirects to www.music-chart.info/japan
etc...

but www.music-chart.info redirects to www.music-chart.info/www and I don't want it too.

The code I currently have in my .htaccess is:

Code:
RewriteCond %{HTTP_HOST} ^(www\.)?([^.]+)\.music-chart\.info
RewriteRule ^$ http://www\.music-chart\.info/%2 [R=301]

Thanks,
Richard
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
Nevermind... this worked:

Code:
RewriteCond %{HTTP_HOST} !^www\.music-chart\.info$
RewriteCond %{HTTP_HOST} ^([^.]+)\.music-chart\.info$
RewriteRule ^$ http://www\.music-chart\.info/%1 [R=301]

If theres a better way to do this, let me know.
 
0
•••
The way you have it now is the best way that I can think of
 
0
•••
The way you have it now is the best way that I can think of

Asking web hosting provider to do that redirect on the side of the server is the best option as for me.
 
0
•••
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back