---
title: "Create an HTTP policy"
sidebar_label: "Create an HTTP policy"
sidebar_position: 3
description: "How to create an HTTP policy in a load balancer rule"
---

import Formbricks from '@theme/MDXComponents/Formbricks'
import Tabs from '@theme/Tabs'
import TabItem from '@theme/TabItem'
import {TabItemLabel} from '@selectel/docux/components'
import MoreVerticalIcon from '@selectel/docux/icons/more-vertical'

# Create an HTTP policy

There is no limit to the number of HTTP policies in a rule or the number of conditions in an HTTP policy.

<Tabs queryString="create-http-policy">
  <TabItem value="panel" default>
    <TabItemLabel>
      Control panel
    </TabItemLabel>

    1. In the [Control panel](https://my.selectel.ru/vpc/default/lbaas/load-balancers/), on the top menu, click **Products** and select **Cloud Servers**.

    2. Go to the **Load Balancers** section → **Load Balancers \*\*\*\* tab**.

    3. Open the load balancer page.

    4. Open the rule card.

    5. Click **Add New Policy**.

    6. Select the parameter to check the request against: `HOSTNAME` for a domain name or `PATH` to check the path.

    7. Select the match type for the control value:

       * `EQUAL TO` — equals;
       * `STARTS WITH` — starts with;
       * `ENDS WITH` — ends with;
       * `CONTAINS` — contains;
       * `REGEX` — regular expression.

    8. Enter the control value for verification. If you selected the `REGEX` condition in step 7, enter a regular expression.

    9. Optional: to add another condition to the policy, click **New Condition** and configure it. If a policy has multiple conditions, the request must match all of them for the policy to apply.

    10. Specify where to redirect a matching request:

        * **Redirect to target group** — select a target group or [create a new one](/cloud-servers/load-balancers/target-groups/create-target-group.mdx) with the HTTP protocol;
        * **Redirect to URL** — enter the target URL that will completely replace the request URL, including the protocol, domain name, path, and request parameters;
        * **Redirect to URL prefix** — enter the part of the URL that should replace the protocol and domain name in the request URL. For example, if you enter `https://example.com/new`, a request to `https://example.com/api` will be redirected to `https://example.com/new/api`

        To not accept requests that match the policy, select **Reject traffic**.

    11. Enter a name for the policy or leave the default one.

    12. Click **Add**.
  </TabItem>

  <TabItem value="openstack">
    <TabItemLabel>
      OpenStack CLI
    </TabItemLabel>

    1. [Open the OpenStack CLI](/cloud-servers/tools/openstack-cli/).

    2. Create an [HTTP policy](/cloud-servers/load-balancers/about-load-balancers.mdx#http-policies) in the rule:

       ```bash
       openstack loadbalancer l7policy create \
         --action <action> \
         [--redirect-url <url> | --redirect-prefix <prefix_url> | --redirect-pool <pool> ]
         --position <position> \
         --name <policy_name> \
         <listener>
       ```

       Specify:

       * `<action>` — the traffic balancing action:

         * `REDIRECT_TO_URL` — completely replace the request URL, including the protocol, domain name, path, and parameters;
         * `REDIRECT_PREFIX` — replace the protocol and domain name in the request URL;
         * `REDIRECT_TO_POOL` — redirect to a target group;
         * `REJECT` — reject;

       * `<policy_name>` — the L7 policy name;

       * where to direct traffic:

         * `--redirect-url <url>` — the full URL for redirection. Specify this if the `REDIRECT_TO_URL`` action is selected`;
         * `--redirect-prefix <prefix_url>` — the URL prefix to replace the protocol and domain in the request, for example `https://example.com`. Specify this if the `REDIRECT_PREFIX`` action is selected`;
         * `--redirect-pool <pool>` — the target group ID or name. Specify this if the `REDIRECT_TO_POOL` action is selected. You can view the list by running the `openstack loadbalancer pool list` command. If you do not have a target group yet, [create one](/cloud-servers/load-balancers/target-groups/create-target-group.mdx).

       * `--position <position>` — the policy position in the rule. Specify this if the rule has multiple policies with the same action; the policy at position `1` will be applied first;

       * `<listener>` — the rule ID or name. You can view the list by running the `openstack loadbalancer listener list`.

    3. Create a condition in the HTTP policy:

       ```bash
       openstack loadbalancer l7rule create \
         --compare-type <compare_type> \
         --type <type> \
         --value <value> \
         <policy>
       ```

       Specify:

       * `<compare_type>` — the match type for the control value:

         * `EQUAL TO` — equals;
         * `STARTS WITH` — starts with;
         * `ENDS WITH` — ends with;
         * `CONTAINS` — contains;
         * `REGEX` — regular expression;
       * `<type>` — the request parameter to check: `HOST_NAME`, `PATH`, `COOKIE`, `FILE_TYPE`, `HEADER`;
       * `<value>` — the control value;
       * `<policy>` — the ID or name of the L7 policy you created in step 2.
  </TabItem>
</Tabs>

<Formbricks />
