What is n8n?
What redirect have you created?
https://n8n.io/ is a workflow automation platform
Redirection created:
Source URL: /wp-json/custom/v1/precourse-redirect
Query Parameters: Exact match in any order
Match: URL only
When matched: Redirect to URL
Target URL: https://see.architdz.tempurl.host/http-responses2wpn/
FYR, I had added a Basic Redirect with the Redirection Plugin (No Custom Endpoint)
Source URL: Set a URL pattern that doesn’t involve the REST API, such as /precourse-check
Tested in browser, https://see.architdz.tempurl.host/precourse-check it redirected to
Target URL: https://see.architdz.tempurl.host/http-responses2wpn/
correctly.
But tested with https://see.architdz.tempurl.host/wp-json/custom/v1/precourse-redirect got 404 error, so sounds REST API issue.
While tested with the default WordPress REST API endpoint by visiting https://see.architdz.tempurl.host/wp-json/ , responded correctly without 404 error.
Really got confused, any idea?
Thanks
It’s not possible to redirect a REST API route.
Hi @johnny5
Below is the answer from ChatGPT when I asked “Is it possible to redirect a REST API route?” Can you help me to clarify whether it is possible or just AI hallucination? Thank you!
Yes, it’s possible to redirect a REST API route, but it depends on how the redirection should be handled and the specific environment. Here are a few options:
- Server-side Redirect: In server-side applications, you can configure the API endpoint to respond with a
3xx
status code (like 301
for permanent redirection or 302
for temporary redirection) along with a Location
header pointing to the new URL. This will tell the client to make a request to the new route.Example in Express.js:javascript複製程式碼app.get('/old-route', (req, res) => { res.redirect(301, '/new-route'); });
- Client-side Handling: If your API client can handle redirects, then you could include the redirect logic directly in the client. You could use a
3xx
status response and a Location
header, or return a JSON response with information on where to go next. This approach might be useful if you’re working with single-page applications or have restrictions on direct redirects.
- Reverse Proxy: If you’re using a reverse proxy like NGINX or a load balancer, you can configure it to redirect specific routes to new endpoints without modifying the application code. This is particularly useful if you want the redirection to happen transparently for clients.
- Middleware Redirects: For frameworks that support middleware (e.g., Express, Django), you can set up middleware that checks the requested route and redirects to the appropriate endpoint before it reaches the main handler.
That doesn’t seem relevant to WordPress or Redirection. I was just referring to Redirection.
Hi @johnny5
If redirect a REST API route is not possible, any other method or suggestion that can help to redirect from n8n as a external agent?
Thanks