Hi, I wish to make folders (i.e. mysite.com/folder) into a subdomain (i.e. folder.mysite.com). I have found this: http://www.hm2k.com/posts/creating-subdomains-from-directories-using-mod_rewrite-in-apache-htaccess The idea was to have the ability to create unlimited subdomains simply by creating an appropreate directory for it in your html root directory. Since most people don’t have direct access to their httpd.conf, the obvious solution was to create a method using mod_rewrite within “.htaccessâ€. This also allowed it to be setup very easily and quickly. I have no immediate use for this solution, however I know it will come in very handy in the future. Someone I know was trying to figure this out earlier today, so I took it upon myself to figure out how to work out a solution for this problem. After much discussion with #apache @ EFnet, in particular TBF, we came about the following solution. #Grab the subdomain from the domain RewriteCond %{HTTP_HOST} ^([^.]+).hm2k.org$ #Make sure the subdomain is not www or example RewriteCond %{1} !^(www|example)$ #Check if the directory actually exists before we go there RewriteCond /home/hm2k/public_html/%1 -d #This stops it from looping RewriteCond %{REQUEST_FILENAME} !^/home/hm2k/public_html/ #Finally, this is the actual rewrite RewriteRule (.*) /home/hm2k/public_html/%1/$1 [Last] Thanks to all those who helped, I hope this comes in useful to someone. Code (markup): But, it doesn't seem to be working. Anyone have any ideas on how to make this work, or another way to do it? Or maybe do I have to modify anything else? Thanks, Owen.
Make sure you modify the paths listed there ("/home/hm2k/public_html") into those appropriate for your site.
I've tried both: #Grab the subdomain from the domain RewriteCond %{HTTP_HOST} ^([^.]+).MYDOMAIN.com$ #Make sure the subdomain is not www or example RewriteCond %{1} !^(www|example)$ #Check if the directory actually exists before we go there RewriteCond /home/owen/public_html/%1 -d #This stops it from looping RewriteCond %{REQUEST_FILENAME} !^/home/owen/public_html/ #Finally, this is the actual rewrite RewriteRule (.*) /home/owen/public_html/%1/$1 [Last] Code (markup): and #Grab the subdomain from the domain RewriteCond %{HTTP_HOST} ^([^.]+).MYDOMAIN.com$ #Make sure the subdomain is not www or example RewriteCond %{1} !^(www|example)$ #Check if the directory actually exists before we go there RewriteCond /public_html/%1 -d #This stops it from looping RewriteCond %{REQUEST_FILENAME} !^/public_html/ #Finally, this is the actual rewrite RewriteRule (.*) /public_html/%1/$1 [Last] Code (markup): Tried that one cos its shared hosting so wasn't sure if I needed to do the home/owen... etc. And none of those worked. Any more ideas?
hello nick-a post a good link ! to add this type nano /var/named/yoursite.com.db add * IN CNAME yourdomainhere.com save file restart named open /etc/httpd/conf/httpd.conf add in ServerAlias *.yourdomain.com yourdomain.com close restart httpd done you now create your subdomains
Ok, well, I've added a *.mysite.com to the httpd.conf file, and also a *.mysite.com. as an A Record. Now, If I type in any site address, i.e. amsdfsdfadf.mysite.com or adsfjasdjfjadksfkjsjfadsjklfd.mysite.com, it goes to my websites homepage (mysite.com). How would I fix this up so that it would go to the directory? Any help would be appreciated, Owen.
ojm now you need create a script or use htaccess ! RewriteEngine On RewriteCond %{HTTP_HOST} !^www\.sitename\.com$ RewriteCond %{HTTP_HOST} ^.+\.sitename\.com$ RewriteCond %{REQUEST_URI} !index.php$ RewriteRule ^(.*)$ %{HTTP_HOST}$1 [C] RewriteRule ^(.+)\.sitename\.com/.* /$1/index.php well if need more help please pm to me best
ok estevan, i use you example and work but, now i need a directory in that subdomain example: http://pdo-explorer.softutopia.com/ works but http://pdo-explorer.softutopia.com/download not foud this links i need to bi rewrite as follow: http://pdo-explorer.softutopia.com/ in to /index.php?a=prog&det=$1 and http://pdo-explorer.softutopia.com/download in to /index.php?a=prog&det=$1&download please help me with a solution