I want to migrate my WP blog to ghost, the permalinks have the same slug (/blogWP.com/title-article and blogGhost.com/title-article) but I still have pages such as blog.com/category for instance to redirect.

Is there any way to make 301 redirections in Ghost as I would do in a .htaccess file ?

Thx !

有帮助吗?

解决方案

It's possible to redirect through ghost itself directly, but you need to alter the core. Though I'm not sure it's the perfect or proper way.

open core/server/errorHandling.js

find this line:

error404: function (req, res, next) {

Add below:

res.status(301); 
res.set({'Location': 'http://your-new-wordpress-blog-url'+req.url});
res.send('301','Not found');

This way, Instead of showind 404s, I redirect to my wordpress' new domain (http://your-new-wordpress-blog-url in the example)

This way, www.ghost.url/not-a-valid-page will redirect to http://your-new-wordpress-blog-url/not-a-valid-page instead of showing the Ghost's 404 page.

p.s: This redirects, but I'm not 100% sure the headers are correct, I'd appreciate if someone else would clarify.

其他提示

I'm sorry, but there is currently no way to do redirects with Ghost.

The best way to do redirects is to use a proxy server (recommended) and do the redirects there. For Apache you could use .htaccess files and nginx offers HttpRewriteModule.

My ghost blog is a subdirectory /blog/ runing with NGINX. I needed to redirect old wordpress urls /blog/category/post-title to /blog/post-title

Except for /blog/ghost/.., /blog/tag/.., /blog/author/.., /blog/post-title/amp/.

So I came with that rewrite rule : rewrite ^/blog/(?:(?!ghost|tag|author).).*/(?:(?!amp))(.+)$ /blog/$1 permanent;

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top