Express req.originalUrl Property

Beginner
⏱️ 8 min read
📚 Updated: May 2026
🎯 4 Code Examples

What you’ll learn

  • What req.originalUrl stores during request handling.
  • How it differs from req.url and req.path.
  • How to use it for logging and debug tracing.
  • How mounted routers affect URL-related request properties.

Usage syntax

javascript
req.originalUrl
req.url
req.path
1

Log original URL in middleware

javascript
app.use(function (req, res, next) {
  console.log('Original URL:', req.originalUrl);
  next();
});
2

Compare URL values in mounted router

javascript
var adminRouter = express.Router();

adminRouter.get('/users', function (req, res) {
  res.json({
    originalUrl: req.originalUrl, // /admin/users?active=true
    url: req.url,                 // /users?active=true
    path: req.path                // /users
  });
});

app.use('/admin', adminRouter);

❓ FAQ

It is the original request URL path and query string as received by Express before internal URL rewriting.
req.url can be modified during routing/middleware mounting, while req.originalUrl preserves the incoming value.
Yes. It includes the query string portion of the incoming URL.
Use it for logging, auditing, redirects, and debugging full request flow through middleware stacks.
It stays stable, while req.url may change as Express strips mount prefixes internally.
Did you know?

req.originalUrl keeps the original request path (including query string) before internal rewrites to req.url in mounted middleware.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

4 people found this page helpful