Skip to content

How to redirect www.example.com to example.com? #2336

Discussion options

You must be logged in to vote

This is actually fairly simple. First, you need to detect that the client has made a request for www.ex.com rather than ex.com, which can be checked via the Host header. Request has a specific method for checking the host (note that if the Host is not sent, you CANNOT identify what domain the user-agent is actually requesting). Then, simply redirect to the correct domain, via the same Redirect method. I recommend using the uri!() macro if possible.

However, I'm also curious what the utility of this is. Rocket's default behavior is to ignore the trailing slash, and by default, unless you create specific Fairings to differentiate the various subdomains, Rocket will ignore the subdomain. The…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@Glitchy-Tozier
Comment options

@the10thWiz
Comment options

Answer selected by Glitchy-Tozier
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants