-
I'm using urltracker in a headless environment, so the url requests are coming through via an api call, rather than from the umbraco front end. I've looked at the source code, but haven't been able to figure out how it matches the requested url to a redirect (if any). I found UrlTrackerRedirectMiddleware, but I haven't been able to reach a solution based on the code there. I could brute force this by getting all of the redirects using the redirect service, but since this api will be called on each page visit, I would like to get it the same way UrlTracker does for normal front end requests to optimize performance. Any ideas on how I should do this? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
Hi @jaandrews !! That's an excellent question and I should be able to help you with that. To find a redirect in custom code, you need to inject the Keep in mind that an intercept is an intentionally vague model as an intercept might not always be a redirect. You will have to map this intercept model to a viewmodel if you want to pass it to the frontend. I hope that is enough to get you going, let me know if you have any questions about this or if you run into any issues. |
Beta Was this translation helpful? Give feedback.
-
@D-Inventor Just so you are aware, I did run into some weirdness with this functionality. When running locally, the redirect fired properly when the source url was relative ("/test/") or absolute ("https://localhost:12345/test/"). However, when I deployed it to azure, only the relative path worked for some reason now. The absolute url ("https://www.example.com/test/") fails to match a redirect. I copy/pasted the source url from the front end multiple times, so I know it's not a typo. You can see a few test cases I made in the below screenshot (site isn't actually pointed at www.example.com; I just used it as a placeholder to avoid exposing the url of the under development site). Any idea why this might be happening? |
Beta Was this translation helpful? Give feedback.
@D-Inventor Thanks for the input. I was able to figure out the problem. I was using the intercept service you suggested, but wasn't getting the expected redirect response. Turns out the problem was that the redirect was entered as a relative url, and it needed to be an absolute url since umbraco had a full domain set for its hostname. Below is my code for anyone else that tries to implement this.