nginx 位置修复 : Redirect to index. html

daizhj 阅读:29 2024-02-27 23:08:18 评论:0

我正在运行 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]/etc/nginx/myconf.conf 中的未知指令“”

提前致谢。

请您参考如下方法:

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

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; 


标签:nginx
声明

1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

关注我们

一个IT知识分享的公众号