> For the complete documentation index, see [llms.txt](https://docs.serverlessapigateway.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.serverlessapigateway.com/configuration/add-and-remove-prefix.md).

# Add and Remove Prefix

Add or remove URL path prefixes when proxying requests in the Serverless API Gateway. Rewrite or strip path segments before forwarding to upstream servers.

````json
{
    ...
    "servers": [
        {   
            "alias": "prefixing",
            "url": "https://sub.serverlessapigw.com/prefix/"
        },
        ...
    ],
    ...
    "paths": [
        {
            "method": "GET",
            "path": "/{.+}",
            "integration": {
                "type": "http_proxy",
                "server": "prefixing"
            }
        },
```
````

With the above configuration, any GET request to the API will be proxied to `'https://sub.serverlessapigw.com/prefix'`.

For example: `GET https://api.yourdomain.com/path` will be proxied to `GET https://sub.serverlessapigw.com/prefix/path`.

This method can also be used to remove a portion of the path from the beginning:

````
{
    ...
    "servers": [
        {   
            "alias": "prefixing",
            "url": "https://sub.serverlessapigw.com"
        },
        ...
    ],
    ...
    "paths": [
        {
            "method": "GET",
            "path": "/prefix/{.+}",
            "integration": {
                "type": "http_proxy",
                "server": "prefixing"
            }
        },
```
````

With this configuration, `GET https://api.yourdomain.com/prefix/path` will be proxied to `GET https://sub.serverlessapigw.com/path`.

### See Also

* [Paths](/configuration/paths.md) -- full reference for path-based routing configuration including methods, auth, and mappings.
* [Servers](/configuration/servers.md) -- define the upstream server aliases used in prefix-based routing.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.serverlessapigateway.com/configuration/add-and-remove-prefix.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
