我有一个旧的php网站,我想转移到Gatsby。但是,它使用以下永久链接结构:
http://example.com/?qa=2/my-awesome-post
我正在使用Gatsby Starter Blog主题,但是其中的网址如下:
http://example.com/my-awesome-post
由于SEO原因,能够调整永久链接结构至关重要。但是,如果我尝试仅更改文件夹结构,则会出现错误“?”。文件或文件夹名称中不允许使用字符。有没有办法在Gatsby网站的url结构中包含特殊字符?请帮助!
如果仅通过将新的.js
文件创建到pages
文件夹中从头开始创建这些页面,则可以考虑覆盖onCreatePage
中的gatsby-node.js
方法。
示例:
exports.onCreatePage = ({ page, actions }) => {
const { createPage, deletePage } = actions;
// First delete the incoming page that was automatically created by Gatsby
deletePage(page);
// then create a new one with proper url
return createPage({
...page,
path: 'update-to-your-needs'
})
}
[例如,如果是从markdown文件动态创建的,则您也可以覆盖它们在gatsby-node.js
中的创建方式。