Forem Creators and Builders

Varhal
Varhal

Posted on

301 redirect after migration content from wordpress

Hey!

We are currently writing a script for migrating content from wordpress to forem. The site on wordpress has more than 1000+ articles that rank well in google, so we want to make 301 redirects from old pages to new ones.

During migration, all links changed their url, making one general redirect from domain to domain is not possible. I need to re-redirect each page manually.

How is it possible to make a massive 301 redirect using forem? Forem is installed on digitalocean. thanks

Discussion (6)

Collapse
ben profile image
Ben Halpern

This is a very exciting case because we would love to see more migrations like this. Each one may be slightly different, but we'll be doing well if we can support this in general.

This will be moving from one domain to another? So the Forem itself won't be able to have awareness of the logic that sends it there. I suspect using Cloudflare workers would be a good tool for this.

Coming up with the right script will take some thought. I have some thoughts on some tooling on the Forem side which could make this generally easier, but if you could give some examples of what the slugs look like on the wordpress side to have a better sense of the specifics, it would be great.

My initial thought is that we could create an endpoint in Forem which takes a given slug and redirects to its "best guess" β€” as far as preserving links in this type of case I'd think it would likely be pretty useful.

To use this post as an example, if you had it on Wordpress with 301-redirect-after-migration-content-from-wordpress as a slug, we could create an endpoint that was like forem.dev/best-guess/301-redirect-after-migration-content-from-wordpress which you could send to, not knowing the ultimate slug` and it could send you to its best guess based on internal logic to match the non-randomly-generated portion of the slug and do some fuzzy matching if there is nothing immediately found, and then if nothing is found it could just redirect home.

I'd think that that tool could probably achieve 95% + success rate.

Just riffing on the idea β€” more details would be helpful, but let me know what you and others think.

Collapse
varhal profile image
Varhal Author • Edited on

We don't want to change the domain, we just want to change the CMS, move from wordpress to forem. Now links to articles look like this:
example.com/bottom-sheets-ios-android-design-ux
and after migration they will look something like this:
example.com/user/bottom-sheets-ios-android-design-ux-j4i5
that's why we need a 301 redirect.

If I understand you correctly, you suggest, on the forem side, to make the links wrap without change, that is, the ending -j4i5 is not added.

Then you only need to make one redirect, which can be done using cloudflare:

example.com/slug redirect to example.com/user/slug

And if such a slug is not found, then the redirect will be to the main page, is that all right?

This would greatly simplify the article migration. There are no problems with redirecting from the old domain to the new domain. It is not clear how such a redirect can work on the same domain.

Collapse
ben profile image
Ben Halpern

This was helpful to understand in detail β€” I have some thoughts about how we could handle some of this. I suspect there is a path of how you could accomplish this in the nearterm for your specific case and how we handle all possible scenarios. Our team will give this some thought and try to help this get worked out.

Thread Thread
varhal profile image
Varhal Author

Fine. We will finalize our migration script for now. All possible types of content need to be considered

Collapse
varhal profile image
Varhal Author

As an idea. When submitting an article for publication via the API, specify in the request:

  • Redirect or not (true / false)
  • url from which you need to make a redirect
Collapse
ben profile image
Ben Halpern

Regarding the API questions at the end, I think that could use its own post.