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条)

报告相同问题?

悬赏问题

  • ¥35 平滑拟合曲线该如何生成
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集