gamehead200 Posted May 20, 2004 Share Posted May 20, 2004 For those of you that run little webservers at home and that don't have cPanel (), here is a nifty trick that will allow you to create your very own subdomains...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 OnRewriteCond %{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 OnRewriteCond %{HTTP_HOST} !^www\.yoursite\.comRewriteCond %{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! Link to comment Share on other sites More sharing options...
XtremeMaC Posted May 20, 2004 Share Posted May 20, 2004 wow niceevery day u get closer to be a pro in this web business Link to comment Share on other sites More sharing options...
Carmon Posted May 21, 2004 Share Posted May 21, 2004 Everyday dat **** Canada Gameshead get clever must kill him lol jk how u access the .htaccess file? Link to comment Share on other sites More sharing options...
gamehead200 Posted May 21, 2004 Author Share Posted May 21, 2004 Everyday dat **** Canada Gameshead get clever must kill him lol jk how u access the .htaccess file? If you're using Linux, I believe you need to unhide it since files that start with "." are hidden...If there isn't one presently on the server, you can send it via FTP... Make the file with Notepad! Link to comment Share on other sites More sharing options...
shortiee4 Posted October 28, 2004 Share Posted October 28, 2004 I can't seem to get a subdomain working with my domain i tried using the .htaccess file but it still doesn't work. Do I need to register the subdomain with dns or anything? i'm confused could someone walk me through how to do this? Link to comment Share on other sites More sharing options...
newdarkness Posted December 12, 2004 Share Posted December 12, 2004 Hello, When I am making this .htaccess for my page, it is working, but suddenly all directories of my server need authentification, what should I do? Link to comment Share on other sites More sharing options...
matrix0978 Posted January 10, 2005 Share Posted January 10, 2005 shortiee4, you might just want to add and subdomain from your host...If not the host might now let you have subdomains. But if its off you computer then i dont know. Youll have to ask Gamehead For that one.! Link to comment Share on other sites More sharing options...
murtuzahsn Posted March 2, 2010 Share Posted March 2, 2010 Thanks for such a great post. I have added the following line in my htaccess file:RewriteCond %{HTTP_HOST} !^www\.mywebsite\.com [NC]RewriteCond %{HTTP_HOST} ([^.]+)\.mywebsite\.com [NC]RewriteRule ^(.*)$ http://www.mywebsite.com/controller/action/%1 [L]When i give the above, the page content is showing what i was expecting, but the problem i am facing is the page URL is also getting changed. I dont want that. What should i do? Is there something in the server that needs to be done? Please suggest.I am working with CakePHPThanks.For those of you that run little webservers at home and that don't have cPanel (), here is a nifty trick that will allow you to create your very own subdomains...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 OnRewriteCond %{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 OnRewriteCond %{HTTP_HOST} !^www\.yoursite\.comRewriteCond %{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! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now