> ## Documentation Index
> Fetch the complete documentation index at: https://ngrok.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# URL Rewrites Examples

> Learn how to rewrite URLs using Traffic Policy to map user-friendly URLs to backend permalinks for better SEO and user experience.

With Traffic Policy, you can map permalinks to "pretty" alternatives that are easier for both humans and [SEO bots](https://developers.google.com/search/docs/crawling-indexing/googlebot) to understand. This is especially useful for blogs that use a CMS, since the generated permalinks might be affecting your SEO performance.

This rule rewrites a user-friendly URL like
`/blog/11/example-title` to `/blog/index.php?p=11&title=example-title`, which is readable by your CMS.

<CodeGroup>
  ```yaml policy.yml theme={null}
  on_http_request:
  - expressions:
    - req.url.path.startsWith('/blog')
    actions:
    - type: url-rewrite
      config:
        from: "/blog/([0-9]+)/([a-zA-Z]+)/"
        to: "/blog/index.php?p=$1&title=$2"
  ```

  ```json policy.json theme={null}
  {
    "on_http_request": [
      {
        "expressions": [
          "req.url.path.startsWith('/blog')"
        ],
        "actions": [
          {
            "type": "url-rewrite",
            "config": {
              "from": "/blog/([0-9]+)/([a-zA-Z]+)/",
              "to": "/blog/index.php?p=$1&title=$2"
            }
          }
        ]
      }
    ]
  }
  ```
</CodeGroup>

See [the `url-rewrite` Traffic Policy action docs](/traffic-policy/actions/url-rewrite/) for more information.
