Welcome to WebmasterWorld Guest from

Forum Moderators: Ocean10000 & phranque

Message Too Old, No Replies

subdomains and redirection

subdomain .htaccess redirect



11:22 am on Aug 17, 2003 (gmt 0)

Inactive Member
Account Expired


I work at a firm that offers webhosting, and I want to host my site there. I don't work near the server so I won't get to configure it because it's somebody else's job. I will tell the administrator to create a virtual host for :
ServerName www.domain.com
ServerAlias *.domain.com

And I will not go to tell him to add me a new virtual host for every subdomain I want, so that's why I need a way to redirect using any means possible :D.
I've created a script using javascript and php to redirect every <subdomain>.domain.com to www.domain.com/<subdomain> but this doesn't work if i get <subdomain>.domain.com/image.jpg .
Is there a way using .htaccess file to get all the <subdomain>.domain.com/<file> from www.domain.com/<subdomain>/<file> and for the URL from the browser not having to change?
7:36 pm on Aug 17, 2003 (gmt 0)

Senior Member

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 31, 2002
votes: 0


Welcome to WebmasterWorld [webmasterworld.com]!

Maybe something like this in .htaccess:

Options +FollowSymLinks
RewriteEngine on
RewriteCond {HTTP_HOST} !^www\.
RewriteCond {HTTP_HOST} ^([^\.]+)\.yourdomain\.com
RewriteRule ^(.*)$ /%1/$1 [L]

Ref: Introduction to mod_rewrite [webmasterworld.com]