dsh8009271 2016-09-27 00:08
浏览 98
已采纳

我应该使用哪种方法将example.com引导至www.example.com - 重定向.htaccess或DNS记录?

I have found a lot of information how to redirect example.com to www.example.com. Two methods DNS and .htaccess. The problem is that most answers do not provide hosting service type and seems different people recommend different option. I know .htaccess is no brainer for Shared Hosting.

Does anybody know which method is better for VPS?

  • 写回答

2条回答 默认 最新

  • duanhuan7750 2016-09-27 00:48
    关注

    In order of least to most advisable places to issue an HTTP 30X:

    1. DNS
      • Well, it's impossible to perform an HTTP redirect with DNS, so this is right out.
    2. Application [eg: in PHP]
      • You can do it here, but really you want to do as little host-based muckery in the application, mostly of the sake of separation of concerns.
    3. .htaccess
    4. Server/Vhost Config
      • Yes, this is where you should do it. Rewrites and redirects are parsed once at server start, and handled by highly-efficient code.

    Very Late Edit:
    I'd like to add that performing redirects in the application code is not necessarily a bad thing, but for simple www. and other host/infrastructure-level redirects the simplicity can't be beat.

    eg: foo.com to www.foo.com and :80 to :443

    However, if you're also doing application redirects you need to have a bulletproof division between what redirects are handled by the the server and which are handled by the application. Otherwise you can descend into a circle of hell where the application and server disagree on how to redirect.

    If that division is anything less than absolute then you're probably better off simply letting the application manage redirects entirely.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 个人网站被恶意大量访问,怎么办
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制