---
title: url.normalize
summary: null
url: >-
  https://www.fastly.com/documentation/reference/vcl/functions/strings/url-normalize
---

```
STRING url.normalize(STRING url)
```

**Available in:** all subroutines

Normalizes a URL by downcasing the scheme and hostname, removing default ports, decoding unnecessary encodings, and normalizing path segments.
The input can be either a complete URL with scheme and authority, or only the path, query string and fragment portion of a URL, such as `req.url`.
If the input URL is of a scheme other than `http` or `https`, or its syntax is invalid, the URL is returned unchanged.

This function implements URL normalization according to [RFC 9110](https://datatracker.ietf.org/doc/html/rfc9110#section-4.2.3) and [RFC 3986](https://datatracker.ietf.org/doc/html/rfc3986#section-6.2.2). In particular, the following steps are taken:

- The scheme is normalized to lowercase.
- The hostname is normalized to lowercase. IPv6 address hostnames are normalized to lowercase hexadecimal, but not otherwise modified.
- The port, if present, is removed if it matches the default for the scheme (80 for `http` and 443 for `https`).
- An empty path following the scheme and hostname is normalized to `/`.
- Unnecessarily percent-encoded characters in the path are decoded, and encoded characters are normalized to uppercase hexadecimal. The set of characters which do not require encoding are the alphanumeric characters and `-._~`.
- The path segments `/./` and `/../` are interpreted and removed.
- Any query string, if present, is preserved unchanged.
- Any fragment, if present, is discarded.

## Example

```vcl
# Example req.url: /foo/../foo%3dbar
set req.url = url.normalize(req.url);
# req.url is now /foo%3Dbar

# Construct a complete normalized URL for the request
declare local var.url STRING;
set var.url = url.normalize(req.protocol "://" req.http.host req.url);
```
