FOR APACHE ONLY! IIS DOES NOT SUPPORT THIS!
First off, say you want http://msfn.yoursite.com to redirect to http://www.msfn.org, then you would put the following in the .htaccess file in the root of your server:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^msfn.yoursite.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.msfn.yoursite.com$
RewriteRule ^(.*)$ http://www.msfn.org/ [L,R=301]
This basically redirects it to msfn.org!
And now, let's say you want a random subdomain to redirect to a random folder on your server... For example, let's say you type in http://something.yoursite.com in your browser... This rewrite rule should make it redirect to http://www.yoursite.com/something ... Now if you do or do not have a folder called "something" on your server, that's another story. If its there, it'll redirect, it if its not, it'll give you a 404!
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.yoursite\.com
RewriteCond %{HTTP_HOST} ([^.]+)\.yoursite\.com [NC]
RewriteRule ^(.*)$ http://www.yoursite.com/%1 [L,R]
The %1 is a variable, so therefore whatever gets placed before .yoursite.com will be in place of that variable.
If anyone has any suggestions or comments, post them here and i'll be glad to help out!



Help
Back to top










