We recently launched an internal website. This website doesn’t have a landing page and provides the feature on a URL path. We wanted to redirect all requests navigating the root path /
to the feature page using nginx. Here’s how we solved it.
nginx Series Overview
- How To Install the Newest Version of Nginx on Ubuntu
- How to Run GitLab with Self-Signed SSL Certificate
- How to Fix Reponse Status 0 (Worker Process Exited on Signal 11)
- Redirect Only Root URL Path
- Remove an App/Domain from Sites-Enabled
- How to Serve a Static HTML Page
- Is Running but Not Serving Sites
- How to Fix Unknown "connection_upgrade" Variable
Redirect the Root URL Path
This nginx rule redirects only the root URL to the defined domain:
location = / {
return 301 https://your-site.com/feature-page;
}
The =
in location = /
specifies an exact match of the URL. This rule won’t match if anything precedes or follows the forward slash. Make sure to define another rule that handles URLs other than the root path.