【问题标题】:react always redirect to homepage反应总是重定向到主页
【发布时间】:2018-01-10 15:19:15
【问题描述】:

首先我是新手,所以我还在学习它。

如果我从另一个域/站点创建超链接以响应本地主机上的应用程序,例如http://localhost:8089/foo/bar,我会遇到这个问题。它直接显示正确的页面,但如果我使用 https 协议从另一个域/站点到公共域的超链接,例如https://example.com/foo/baz,它总是重定向到主页页面(https://example.com/

我能做些什么让它直接转到https://example.com/foo/baz。我使用此重定向设置在 nginx Web 服务器上运行 react,它适用于 php、django 等,但不会在 react 中运行。

server {
    listen 80 default_server;
    listen [::]:80 default_server;
    server_name example.com;
    return 301 https://$server_name$request_uri;
    root /home/[path to dist folder]/web/app/dist;
    index index.html index.htm;

}

仅供参考,react 应用程序是使用 webpack 构建的,在此先感谢

【问题讨论】:

    标签: reactjs redirect nginx


    【解决方案1】:

    我的问题是:

    "return 301 https://$server_name$request_uri;"
    

    你应该替换它:

    "return 301 https://$server_name/$request_uri;"
    

    【讨论】:

    • 可以给我完整的配置吗?
    【解决方案2】:

    我已经设法为文件设置了正确的配置。

    应该是这样的

    server {
        ...
        location / {
            ...
            try_files $uri $uri/ /index.html;
        }
        ...
    
    }
    

    感谢大家的帮助

    【讨论】:

      猜你喜欢
      • 2020-06-14
      • 2016-10-02
      • 2019-02-01
      • 2014-07-10
      • 2018-02-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多