0

I have always wondered how can I do this..

if you go https://community.nodebb.org/topic/14103/strange-thing-on-this-forum

It shows a thread in a forum.

But you can actually access to that same page with https://community.nodebb.org/topic/14103

and then this url changes to the 1st one above.

How can I do this in Node.js?

Kam
  • 63
  • 11
  • Looks like a redirect... add a response [similar to this one](https://stackoverflow.com/a/4062281/10431732) on the route you want to redirect, voila. NOTE: the route you are redirecting to must be an active/available route..(obviously).. EDIT2: [Or if you are using Express..](https://stackoverflow.com/a/19038048/10431732) – Matt Oestreich Jul 15 '19 at 02:29
  • Are you familiar with what happens when a web server returns a [301 Moved Permanently](https://en.wikipedia.org/wiki/HTTP_301) status code? It's called _URL redirection_. Or do you need source code for a particular framework in Node.js? What are you looking for exactly? – Wyck Jul 15 '19 at 04:00

1 Answers1

2

Node itself is just the language, what you're asking about happens in a framework, like Express.
In Express (and most other frameworks) you can define routes based on either strings, symbols, or a regex. In your above example, the route definition is likely looking for topic/:id and also set to accept anything put after the ID.
Look at the basics of Routing in Express to see how this works.

Chase
  • 3,009
  • 3
  • 17
  • 23
  • Your wrong, You do need node to do this, express just uses node in order to accomplish that. you can do it easily by urself(Ive done it, built a small light moudle who route) – Talg123 Jul 15 '19 at 04:08