Web 编程中的子域与子目录 [英] subdomain vs. subdirectory in web programming

查看:39
本文介绍了Web 编程中的子域与子目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在网络上处理多个应用程序"有两种主要策略:

There are two main strategies for handling multiple "applications" on the web:

  • 子域(例如 wiki.example.org、blog.example.org、admin.example.org、api.example.org/v1)
  • 子目录(例如 example.org/wiki、example.org/blog、example.org/admin、example.org/api/v1)

这两种解决方案在处理 Web 编程时(例如在代码组织、浏览器安全模型、javascript 等方面)有什么区别(优点和缺点).

What are the differences (advantages and disadvantages) of these two solution when dealing with web programming (e.g. in terms of code organization, browsers security models, javascript etc).

CW,因为有一个正确的答案,但它非常广泛.

CW as there's a correct answer, but it's very broad.

推荐答案

除了从安全的角度来看,在子域中隔离应用程序更容易一点之外,我将仅评论我认为最大的区别两者之间.

Besides the fact that from a security standpoint it is a bit easier to isolate an app within a subdomain, I will just comment on what I think is the biggest difference between the two.

子域的专业版:

  • 您可以按域隔离配置(例如 apache).
  • 将应用程序的一部分迁移到其他机器会更容易.子目录不会真正为您提供这种灵活性.
  • 不必在每个 html 模板中都使用 $baseUri 变量,您可以假设应用程序的根目录始终为/.

缺点:

  • 快速设置登台或临时开发环境会更烦人.对于每个应用程序",您现在都需要主机文件条目的 DNS 和网络服务器配置.使用子目录,您可以将应用程序放到目录中,然后开始!
  • 如果您确实需要在不同的系统上部署您的应用程序,而使用/是因为某些奇怪的政策是不可能的,那么可能需要进行一些重写.

我的建议:

确保您始终可以同时做到这两点,这将为您提供两全其美的体验.您的应用程序的每个部分都应该有一个始终受到尊重的可配置基础 uri.只要你确保你总是可以双向进行,那么谁在乎你做什么呢?它只是一个网址,可以随时更改.

Make sure you can always do both, which will give you the best of both worlds. Every part of your app should have a configurable base uri that is always respected. As long as you make sure you can always go both ways, then who cares what you do? it's just a url and it can always be changed.

这篇关于Web 编程中的子域与子目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆