GHOST CMS - Redirects

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).

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

时间: 2024-08-01 01:02:56

GHOST CMS - Redirects的相关文章

GHOST CMS - 配置 Config

Config For self-hosted Ghost users, a custom configuration file can be used to override Ghost's default behaviour. This provides you with a range of options to configure your publication to suit your needs. 对于自承载的Ghost用户,可以使用自定义配置文件覆盖Ghost的默认行为.这为您提供

GHOST CMS - 创建自定义主页 Creating a custom home page

创建自定义主页 Creating a custom home page 为你的网站创建一个自定义的主页是一个让你从人群中脱颖而出的好方法,并把你自己独特的印记存放在你的网上.本教程向您展示了如何在Ghost中自定义和开发自己的自定义主页. Creating a custom home page for your site is a great way to set yourself apart from the crowd and put your own unique stamp on you

GHOST CMS -上下文概述 Context Overview

Context Overview上下文概述 Each page in a Ghost theme belongs to a context, which determines which template is used, what data will be available and what content is output by the {{body_class}} helper. Ghost主题中的每个页面都属于一个上下文,它决定使用哪个模板.哪些数据可用以及{{body_class}

GHOST CMS - 索引Index

Index Use: {{#is "index"}}{{/is}} to detect this context. 使用:{{#is "index"}}{{/is}}来检测这个上下文. Description描述 index is the name for the main post list in your Ghost site, the index context includes the home page and subsequent pages of th

GHOST CMS - Data Helpers

Data Helpers Data helpers are used to output data from your site. Use this reference list to discover what each handlebars helper can do when building a custom Ghost theme. Available data helpers @config @site navigation post url title img_url excerp

GHOST CMS - Content Taxonomies

Content Taxonomies Taxonomies are groupings of posts based on a common relation. In Ghost, this is always defined by the post's author or tag Using taxonomies, Ghost will automatically generate post archives for tags and authors like /tag/getting-sta

GHOST CMS - Responsive Images 图片显示

Responsive Images Optimise the performance of your site by outputting images at different sizes depending on where they appear Overview So you upload glorious 2000px feature images to all your posts to appear in the giant hero/header on individual ar

GHOST CMS - Content Collections

Content Collections Collections are the backbone of how posts on a Ghost site are organised, as well as what URLs they live on. You can think of collections as major sections of a site which represent distinct and separate types of content, for examp

GHOST CMS - Handlebars Themes - Further Reading

Further Reading Where you go from here is up to you, the world is your router1 Ghost's dynamic routing system is an extremely powerful way to build advanced structures for your site, and it's hard to document every possible example of what can be don