views:

211

answers:

2

I want to create subdomains manually on my website as in my current hosting plan I have no option of creating a subdomain. I think perhaps this is possible using .htacces???

Please give two examples in answers for agrimgupta DOT com/oranges --> blog DOT agrimgupta DOT com/ and agrimgupta DOT com/work/UniV --> study DOT agrimgupta DOT com/

Thanks in advance

+1  A: 

If your hosting provider does not support subdomains, you will not be able to manage it manually in code or .htaccess files. The reason is because each subdomain needs to exist in your domain's DNS records, or else client apps. will not be able to determine what IP address to connect to.

Remy Lebeau - TeamB
OP doesn't mention whether their DNS is hosted with the same provider - it's certainly possible to setup a wildcard DNS entry and have multiple subdomains point to the same IP address.
pix0r
+1  A: 

This is certainly possible to do, but will depend on your hosting setup.

If you are able to create a wildcard DNS entry, you can map all subdomains of agrimgupta.com to the same IP address. If your web host is giving you a dedicated IP address and using an IP-based virtual host, these domains will all point to your web application. You could then use mod_rewrite or a custom index.php file to route the requests to different resources based on the subdomain.

Note that you will run into some hurdles here trying to re-map files to the proper directories.

This sample mod_rewrite code will do a simple redirect when you access blog.agrimgpta.com and point the user to the files under /oranges. The user won't actually be "browsing" under blog.agrimgupta.com however - that will take some more effort to accomplish. (At that point, you may just consider switching to a web host that will support multiple domains/subdomains.)

<IfModule mod_rewrite.c>
    RewriteCond %{HTTP_HOST} blog.agrimgupta.com
    RewriteRule /$ http://www.agrimgupta.com/oranges/ [R=301,L]
</IfModule>
pix0r
Thanks for the detailed reply!So basically this will just redirect the an entered uri of blog.agrimgupta.com and take the user to agrimgupta.com/oranges ? or is there something that i didn't get?I'm using profusehost (200MB) fully free plan
OrangeRind
Yes, that's correct, assuming you can get the wildcard hostnames to map to the same site. Many large virtual hosts will use name-based virtual hosting, rather than IP-based, in which case this probably won't work (without changes to the web server's config).
pix0r
The only gotcha is the web browser has to support the HTTP 'Host' header in order to specify which subdomain was used. Otherwise, there would be no other way for the application to detect the subdomain if they all go to the same IP.
Remy Lebeau - TeamB