Did not work as expected because the slug part of the URL was generated in the migration-script slighty different as in the old software.
So I “normalized” the URL by my own.
Add/generate normalized URLs (Discourse Permalinks Table)
In the url-field get from
to a simple url with only the id of the old topic:
This is done by a SQL Command which rewrites the URL via the REGEXP_REPLACE function:
INSERT INTO permalinks (created_at, updated_at, topic_id, url) SELECT NOW(), NOW(), topic_id, REGEXP_REPLACE(url,'forum/t(\d*)(-?.*)/(.*)','forum/t\1','') url FROM permalinks WHERE topic_id > 0 ON CONFLICT DO NOTHING;
Rewrite old Requests via .htaccess on the old domain
RewriteRule ^forum/t([0-9]*)(-?.*)/(.*)$ https://discourse-domain.com/forum/t$1 [R=301,L]
So what happens here?
Google has indexed and is linking to the URL
https://old-domain.com/forum/t140842/8p-hilfe-bei-1-8-tfsi-guter-motor-oder-schlechter-motor.html. I was lucky that this request ended on an Apache server because of a different domain and i could use .htaccess to rewrite easily. So I am rewriting this request to
https://discourse-domain.com/forum/t140842. In the permalinks table I added this
forum/t140842 record by using the already added permalink with the whole slugged url using a regex (see above).
Hope this helps somebody else as a starting point.