Forem Creators and Builders 🌱


Posted on • Updated on

301 redirect after migration content from wordpress [resolved]


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

I create bulk redirects with cloudflare workers

!(function (e) {
var t = {};
function n(r) {
if (t[r]) return t[r].exports;
var u = (t[r] = { i: r, l: !1, exports: {} });
return e[r].call(u.exports, u, u.exports, n), (u.l = !0), u.exports;
(n.m = e),
(n.c = t),
(n.d = function (e, t, r) {
n.o(e, t) || Object.defineProperty(e, t, { enumerable: !0, get: r });
(n.r = function (e) {
"undefined" != typeof Symbol && Symbol.toStringTag && Object.defineProperty(e, Symbol.toStringTag, { value: "Module" }), Object.defineProperty(e, "__esModule", { value: !0 });
(n.t = function (e, t) {
if ((1 & t && (e = n(e)), 8 & t)) return e;
if (4 & t && "object" == typeof e && e && e.__esModule) return e;
var r = Object.create(null);
if ((n.r(r), Object.defineProperty(r, "default", { enumerable: !0, value: e }), 2 & t && "string" != typeof e))
for (var u in e)
function (t) {
return e[t];
}.bind(null, u)
return r;
(n.n = function (e) {
var t =
e && e.__esModule
? function () {
return e.default;
: function () {
return e;
return n.d(t, "a", t), t;
(n.o = function (e, t) {
return, t);
(n.p = ""),
n((n.s = 0));
function (e, t) {
const n = new Map([
["/test3", ""],
["/test2", ""],
["/test1", ""],
addEventListener("fetch", async (e) => {
(async function (e) {
const t = new URL(e.url).pathname,
r = n.get(t);
return r ? Response.redirect(r, 301) : fetch(e);

Top comments (6)

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

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:
and after migration they will look something like this:
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: redirect to

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.

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

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
ben profile image
Ben Halpern

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