# Handling root path GET requests via URL routing?

**URL:** <https://erlangforums.com/t/handling-root-path-get-requests-via-url-routing/3393>\
**Category:** Nitrogen Forum\
**Tags:** nitrogen-questions\
**Created:** [March 21, 2024, 5:58pm UTC](https://erlangforums.com/t/handling-root-path-get-requests-via-url-routing/3393 "2024-03-21T17:58:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jbcorwin](https://erlangforums.com/user_avatar/erlangforums.com/jbcorwin/32/2148_2.png) [@jbcorwin](https://erlangforums.com/u/jbcorwin)\
**Post date:** [March 21, 2024, 5:58pm UTC](https://erlangforums.com/t/handling-root-path-get-requests-via-url-routing/3393/1 "2024-03-21T17:58:24Z")

</div>

If I wanted to emulate how Twitter (_X_) accepts a username in the URL via the root path how would I do this with Nitrogen?

Within the index.erl module I can call wf:path\_info() to handle this use case, but what is the way to force all requests to the root that would normally 404 to flow through the index.erl module? Would this need to be handled by modifications to the dynamic\_route\_handler?

Ex: [https://twitter.com/nitrogenproject](https://twitter.com/nitrogenproject)

I have read [Nitrogen - Documentation](https://nitrogenproject.com/doc/route.md) but I was hoping for something like [Routing — Phoenix v1.7.11](https://hexdocs.pm/phoenix/routing.html) that wouldn’t require modifications to the dynamic\_route\_handler provided by Nitrogren.

---

<div class="post-metadata">

**Author:** ![gumm](https://erlangforums.com/user_avatar/erlangforums.com/gumm/32/688_2.png) [@gumm](https://erlangforums.com/u/gumm)\
**Post date:** [March 21, 2024, 6:33pm UTC](https://erlangforums.com/t/handling-root-path-get-requests-via-url-routing/3393/2 "2024-03-21T18:33:38Z")

</div>

Hey @jbcorwin,

The two options available to you are to:

1. Make a custom route handler, or
2. Make a `web_404` module to handle that.

(2) is the easiest. It acts like a normal module, it just has to be named `web_404`. Then you can pull the requested path with `wf:path_info()`

(1) however is more likely the proper solution.

You can make a copy of `dynamic_route_handler.erl` and make a few changes to it to handle some more specific cases.

But at the end of the day, either method works.

I’m also open to the possibility of augmenting the `dynamic_route_handler` to read some sort of configuration rules for pattern-matched routing - since the dynamic\_route\_handler does do a decent amount of stuff.

---

<div class="post-metadata">

**Author:** ![jbcorwin](https://erlangforums.com/user_avatar/erlangforums.com/jbcorwin/32/2148_2.png) [@jbcorwin](https://erlangforums.com/u/jbcorwin)\
**Post date:** [March 21, 2024, 8:10pm UTC](https://erlangforums.com/t/handling-root-path-get-requests-via-url-routing/3393/3 "2024-03-21T20:10:37Z")

</div>

I agree with you that #1 would be the preferred way and to your suggestion of pattern matching in the `dynamic_route_handler` all I have in mind is just a configuration flag to treat unknowns to root to be handled by `index.erl`. Other paths (_Ala reddit style_) can already by managed by the exiting routing/modules - at least that I can think of.

I should add that I’d prefer to have this in the default install versus a separate `dynamic_route_handler` that I have to manage / coalesce through upgrades. I haven’t looked into what that would entail but anytime I can avoid extra work I’ll take it.
