Actix Rust: Collision in routes due to subdomain

This question is related to this question. There I asked if it was possible to deploy two applications on the same domain. It is possible using Nginx reverse proxy, but that is too complicated, unstable and results in a barely functioning web-application.

So I decided to include my website, which was previously a separate Laravel project, also in the Rust part of the application.

My situation:
I have a basic website promoting my application. With URLs like:

My web-application provides an unlimited amount of businesses a personalized page. Each business has his own subdomain. So:

Each business also has their own pages:

The problem I have now: The routes collide!

Business A has his own about page on But my main site also has a about-page on!

Route code:


How would I solve this? I'd need something like:


I could also make a function about_page_check_if_subdomain() which would get executed on both /about-paths. And checks if the HttpRequest contains a subdomain. If so, go to about_page_business_page() else go to about_page_main_site(). But that doesn't sound really solid.

How do I detect if a request is for a subdomain, and if so, give another route then without subdomain?


Using guard::Host

1 Like

I solved it the following way:

                    .guard(actix_web::guard::fn_guard(|header| {

// Function to check if given url contain a subdomain
pub fn url_contains_subdomain(url: &str) -> bool {
    println!("rofl {}", url);

    let url = url.replace("www.", "");
    let mut split: std::vec::Vec<&str> = url.split(".").collect();

    split.len() > 2

Let me know if someone has a more elegant solution.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.