【问题标题】:nginx location fix: Redirect to index.htmlnginx 位置修复:重定向到 index.html
【发布时间】:2011-11-30 20:37:16
【问题描述】:

我正在运行 nginx v 1.0.4,我们正在尝试执行以下操作:

location ~ ^/$ {
  rewrite  ^.*$  /index.html  last;
}

基本上:如果用户访问默认域http://www.foo.comhttp://www.foo.com/ 将他们重定向到http://www.foo.com/index.html

当我将它添加到我的 conf 文件中时,我得到以下信息: 启动 nginx: nginx: [emerg] unknown directive " " in /etc/nginx/myconf.conf

提前致谢。

【问题讨论】:

    标签: nginx


    【解决方案1】:

    你可以在没有位置的情况下使用重写功能

    rewrite  ^/$  /index.html  last;
    

    或永久重定向

    rewrite  ^/$  /index.html  permanent;
    

    用参数重写,例如http://www.foo.com/?param=value -> http://www.foo.com/index.html?param=value

    rewrite  ^/(\?.*)?$  /index.html$1  permanent;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-03-09
      • 1970-01-01
      • 2019-02-02
      • 2017-03-21
      • 1970-01-01
      • 1970-01-01
      • 2020-06-12
      相关资源
      最近更新 更多