简体   繁体   中英

Manual Sub-Domain Construction

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

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>

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM