【问题标题】:How to change the "/blog" of the url in a RefineryCMS app if you set the blog as the root and want to just display the domain?如果您将博客设置为根并且只想显示域,如何在 RefineryCMS 应用程序中更改 URL 的“/blog”?
【发布时间】:2013-09-05 00:51:06
【问题描述】:

我已经将博客设置为根。然后按照http://refinerycms.com/guides/page-titles-and-urls 的教程进行操作,该教程说要更改 Refinery 的默认 slug,我需要修改 config/initializers/refinery/pages.rb 以拥有 config.use_custom_slugs = true 。该部分已完成。

我的博客将进入类似于blog.example.com 的子域,因此如果我有blog.example.com/blog 看起来很糟糕

所以我已经确保将“家”重定向到www.example.com,所以现在我需要知道如何从网址中删除/blog。因此,点击“博客”会将您带到blog.example.com

在高级选项中,我尝试将自定义 slug 设置为“/”,但没有按预期工作。

【问题讨论】:

    标签: ruby-on-rails routing refinerycms


    【解决方案1】:

    您需要更改您的 routes.rb 文件以重定向到博客索引页面。确保在安装 Refinery Core Engine 之前放置它。

    Yourapp::Application.routes.draw do
    
    root :to => 'refinery/blog/posts#index'
    
    # This line mounts Refinery's routes at the root of your application.
    # This means, any requests to the root URL of your application will go to Refinery::PagesController#home.
    # If you would like to change where this extension is mounted, simply change the :at option to something different.
    #
    # We ask that you don't use the :as option here, as Refinery relies on it being the default of "refinery"
    mount Refinery::Core::Engine, :at => '/'
    ...
    

    【讨论】:

      【解决方案2】:

      炼油厂博客引擎初始化程序有一个“page_url”选项,您可以更改。

      在 config/initializers/refinery/blog.rb 中取消注释以下行:

      # config.page_url = "/blog"
      

      把它改成

      config.page_url = "/"
      

      不确定这是否适用于自定义子域,但这是替换默认 '/blog' 路由的方法

      【讨论】:

        【解决方案3】:

        我对 Refinery 的内部结构不是很熟悉,但请尝试将其放在您的 routes.rb 文件的顶部:

        get '/', to: redirect('/blog')
        

        这应该允许你使用你想要的域,虽然我相信它会在渲染之前重定向到/blog

        【讨论】:

        • 哦,我似乎错误地表达了意图。根已经转发到/blog,但我希望地址栏中的 url 只显示没有页面的域。所以只是blog.example.com 而不是blog.example.com/blog
        • 知道了。这里的答案将允许您以blog.example.com 链接到它,然后它会重定向到blog.example.com/blog,用户可能不会注意到。不确定您如何通过炼油厂实现您想要的;如果您知道在 Refinery 中要路由到哪个控制器,那将非常简单,但我不知道。
        猜你喜欢
        • 2023-03-14
        • 2018-11-19
        • 2013-02-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-01-22
        • 2023-04-02
        相关资源
        最近更新 更多