Redirect URL with Nginx in Digital Ocean

I have a ready-made Discourse setup on Digital Ocean.
I want to redirect from Flarum to Discourse but I couldn’t find the nginx folder.

I looked in /etc/ - /usr/ folders but couldn’t find it. I can’t find it because Docker is used?

Can I redirect with regex through the admin interface?

Flarum: https://testdiscourse.com/d/123123-asdasd
Discourse : https://testdiscourse.com/t/asdasd/123123

I want to redirect as above, but I couldn’t find the nginx folder. I would be glad if you help.
Also, if you can share the regex codes, I would appreciate it :slight_smile:

Did you do a standard install or is flarum running on the same host as Discourse?

Did you use the flarum migration script to import your data? It doesn’t look like the flarum script handles permalink redirects. I cannot imagine how the redirect you suggest could possible work unless you have somehow contrived for the topic IDs in Discourse to match those in flarum.

If you somehow did that, there is a permalink normalization site setting that will do what you suggest. It would be something like

     /d\/(\d+)-(.*)/t\/\2\/\1/

But the asdasd section can be replaced with a -, as the slug is ignored for routing.

nginx is inside the docker container. You can see it if you

cd /var/discourse
./launcher enter app

changes that you make there will be destroyed when you build a new container. It’s possible to make changes to your app.yml that will modify the nginx config in the container when a new one is built. You can look at the templates in /var/discourse/templates for some examples.

2 Likes

I entered docker with the ./launcher enter app command.
It’s in nginx :slight_smile: Sorry I’m a beginner.

What file should I configure in nginx? Do you have any knowledge about this topic?

Domain name etc. does it normally appear in this file?

The optimal solution here would be to update the migration script so that the permalink redirects are created for you.

Don’t configure nginx directly, those changes will be destroyed each time the container is rebuilt for an upgrade.

Instead as @pfaffman says edit the app.yml to modify the nginx configuration.

2 Likes

I am making changes in app.yml but how exactly should I do the redirect? :frowning:

I would really appreciate if you could help. There are 150,000+ questions, I don’t want to try to go through them all :frowning:

I have never been redirected in this way before, and according to my research on the internet, I couldn’t find much.

When I write the redirect with rewrite, what I want is:

https://testdiscourse.com/d/123123-asda-asdasd-adas

https://testdiscourse.com/t/asda-asdasd-adas

I don’t even need 123123, how can I do that?

Your destination needs the topic ID, the stub is optional

1 Like

Isn’t it enough to have a slug section?

https://meta.discourse.org/t/redirect-url-with-nginx-in-digital-ocean

For example, when you click on the link above, this page opens.

So it doesn’t need to write 235297.

https://meta.discourse.org/t/cake/235297/ the stub doesn’t impact the redirect - you can have anything before the ID

https://meta.discourse.org/t/235297/ you can even drop the stub entirely

https://meta.discourse.org/t/redirect-url-with-nginx-in-digital-ocean/ this will work but is more fragile

1 Like

Since the id values in Flarum and the id values here are different, the slug values are enough for me.

It’s too bad to do 150,000 questions one by one. I am very tired :slight_smile:

That’s why fixing the import script is the easiest solution

1 Like

There wasn’t any permalink redirect option in the import script but :frowning: I’m also new to Ruby language and postgresql. I would love to but I can’t.

It’s almost certainly going to be quicker to investigate and compare to the other importer scripts and attempt to implement than it will be to create 150,000 redirects manually.

2 Likes

Then you need to modify or pay someone to modify the import script to make the permalinks. What you are trying to do is impossible. The topic ids are all different. If you have users already using the community now you’re either out of luck or will need to throw away their posts.

Oh. Sorry. The import_ids should be in the database. You can write a script to create the permalinks. You’ll need to look at some of the other import scripts for one that creates the redirects after the topics are imported rather than as part of the import topic function.

3 Likes

MVP right here! :man_superhero:

2 Likes

here’s an example:

Sometimes it’s hard to get the right slug for various reasons. You can usually do something clever with permalink_normalizations to ignore the slug and pay attention only to the ID in the Permalink.

4 Likes