【问题标题】:How to rewrite different subdomains as folders within the same site using Netlify如何使用 Netlify 将不同的子域重写为同一站点内的文件夹
【发布时间】:2018-10-10 02:07:51
【问题描述】:

正如https://www.netlify.com/blog/2015/10/30/domain-aliasesas-many-as-you-like/Netlify 中所述,似乎支持这一点:

我们灵活的重写规则也意味着您甚至可以处理不同的 子域作为同一站点内的文件夹。

但是这应该如何配置呢?似乎没有记录在任何地方。

编辑

我想将文件存储在文件夹 /developer 并从 http://developer.example.com 提供它们。所以对于用户来说,他看起来正在浏览http://developer.example.com

【问题讨论】:

    标签: url-rewriting netlify


    【解决方案1】:

    您可以通过在_redirects 文件中定义重定向规则来执行此操作

    将托管在子域上的内容提供给来自文件夹 URL 的请求:

    # proxy the request
    /my/folder/path  https://subdomain.ofmy.site  200
    
    # redirect the request
    /my/folder/path  https://subdomain.ofmy.site  302
    

    您还可以使用通配符和 splats

    # proxy the request
    /my/folder/path/*  https://subdomain.ofmy.site/:splat  200
    

    关于在 Netlify 上定义重定向的更详细文档:https://www.netlify.com/docs/redirects/

    【讨论】:

    • 您好菲尔,谢谢您的回复。我正在寻找相反的东西。所以我希望在http://developer.example.com 上提供像/developer 这样的文件夹
    • 也许这是不可能的,我应该创建一个托管在子域上的第二个站点。
    • @MarcelOverdijk,您有没有找到解决方案,或者您是否必须创建第二个 Netlify 网站并使用子域作为自定义域?
    • 我通过 Twitter 联系了 Netlify 支持,并收到了一些有用的回复。按照他们的指示,我尝试添加指向example.netlify.comsubdomain 的CNAME DNS 记录,然后在我的_redirects 文件中添加一行,这基本上与此答案相反:https://subdomain.example.com/* /subdomain/:splat 200!,但我得到了 404当我访问subdomain.example.com时未找到响应@
    • @PaulShryock 我找到了一个对重写单独的子域应用程序很有用的解决方案:stackoverflow.com/questions/55537324/…
    猜你喜欢
    • 2012-08-20
    • 1970-01-01
    • 2013-05-02
    • 2011-12-10
    • 2013-06-06
    • 1970-01-01
    • 2011-08-05
    • 2023-03-20
    • 1970-01-01
    相关资源
    最近更新 更多