码迷,mamicode.com
首页 > 其他好文 > 详细

GHOST CMS - Redirects

时间:2019-12-23 00:41:48      阅读:112      评论:0      收藏:0      [点我收藏+]

标签:always   star   tps   baseline   ide   res   can   like   auto   

Redirects

In addition to creating routes, you can also create redirects for any time there are any changes in your URLs and you need to forward visitors

Accessing the redirects file

The redirects.json file is located in content/data/redirects.json and - like routes.yaml - can also be downloaded/uploaded in the settings in Ghost Admin.

File structure

This file always starts with a [ and ends with a ]. A new ghost publication will have an empty redirect file containing []. It can be edited in any source code editor.

{
  "from": "/url/" ,
  "to":  "/url/",
  "permanent": true | false
}
  • The from field defines the incoming URL or pattern (regex)
  • The to field defines where the incoming traffic should be redirected to, which can be a static URL, or a dynamic value using regex (example: "to": "/$1/").
  • The permanent field can be defined with true for a permanent 301 redirect, or false for a temporary 302 redirect.

Multiple entries are separated by , and the last entry does not have the ,. Regular expressions can be used to implement redirect patterns.

Implementation

Upload your new redirects.json file in Ghost admin in the settings. This is the recommended method.

To replace the JSON file on the server, ensure it exists in content/data/redirects.jsonand run ghost restart for your changes to take effect.

When not to use redirects.json

There are some instances where it is not recommended to use the redirects.json file:

  • Page rules for www or HTTP/HTTPS redirection should always be implemented with your DNS provider.
  • Ghost automatically forces trailing slashes, so you do not need to write any page rules to accommodate for duplicate content caused by this.
  • If you‘re trying to change the URL structure of your publication, the recommended way to do this is with dynamic routing and the routes.yaml file. (However, you may still need to redirect existing content using redirects.json).

GHOST CMS - Redirects

标签:always   star   tps   baseline   ide   res   can   like   auto   

原文地址:https://www.cnblogs.com/QDuck/p/12081561.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!