简体   繁体   English

手动子域构造

[英]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??? 我认为使用.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/ 请在回答agrimgupta DOT com / oranges的示例中给出两个示例->博客DOT agrimgupta DOT com /agrimgupta DOT com / work / UniV->学习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. 如果能够创建通配符DNS条目,则可以将agrimgupta.com的所有子域映射到相同的IP地址。 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. 如果您的Web主机为您提供了专用IP地址并使用基于IP的虚拟主机,则这些域都将指向您的Web应用程序。 You could then use mod_rewrite or a custom index.php file to route the requests to different resources based on the subdomain. 然后,您可以使用mod_rewrite或自定义index.php文件将请求路由到基于子域的不同资源。

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. 当您访问blog.agrimgpta.com并将用户指向/ oranges下的文件时,此示例mod_rewrite代码将执行简单的重定向。 The user won't actually be "browsing" under blog.agrimgupta.com however - that will take some more effort to accomplish. 但是,用户实际上不会在blog.agrimgupta.com下“浏览”-这将需要更多的努力才能完成。 (At that point, you may just consider switching to a web host that will support multiple domains/subdomains.) (那时,您可能只考虑切换到支持多个域/子域的Web主机。)

<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. 如果您的托管服务提供商不支持子域,则将无法在代码或.htaccess文件中手动对其进行管理。 The reason is because each subdomain needs to exist in your domain's DNS records, or else client apps. 原因是因为每个子域都必须存在于域的DNS记录或客户端应用程序中。 will not be able to determine what IP address to connect to. 将无法确定要连接的IP地址。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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