A.2. Preparing PBX Rewrite Rules

A.2.1. Inbound Rewrite Rules for Caller
A.2.2. Inbound Rewrite Rules for Callee
A.2.3. Outbound Rewrite Rules for Caller

In a PBX environment, the dial-plans usually looks different than for normal SIP subscribers. PBX subscribers should be able to directly dial internal extensions (e.g. 100) instead of the full number to reach another PBX subscriber in the same PBX segment. Therefore, we need to define specific Rewrite Rules to make this work.

The PBX dial plans are different from country to country. In the Central European area, you can directly dial an extension (e.g. 100), and if you want to dial an international number like 0049 1 23456, you have to dial a break-out digit first (e.g. 0), so the number to be dialed is 0 0049 1 23456. Other countries are used to other break-out codes (e.g. 9), which then results in 9 0049 1 23456. If you dial a national number like 01 23456, then the number to actually be dialled is 9 01 23456.

Since all numbers must be normalized to E.164 format via inbound rewrite rules, the rules need to be set up accordingly.

Let’s assume that the break-out code for the example customers created below is 0, so we have to create a Rewrite Rule Set with the following rules.

A.2.1. Inbound Rewrite Rules for Caller

  • Match Pattern: ^([1-9][0-9]+)$
  • Replacement Pattern: ${caller_cloud_pbx_base_cli}\1
  • Description: extension to e164
  • Direction: Inbound
  • Field: Caller

Figure A.9. Inbound Rewrite Rule for Caller

Inbound Rewrite Rule for Caller

A.2.2. Inbound Rewrite Rules for Callee

These rules are the most important ones, as they define which number formats the PBX subscribers can dial. For the break-out code of 0, the following rules are necessary e.g. for German dialplans to allow pbx internal extension dialing, local area calls without area codes, national calls with area code, and international calls with country codes.

PBX internal extension dialin

  • Match Pattern: ^([1-9][0-9]+)$
  • Replacement Pattern: ${caller_cloud_pbx_base_cli}\1
  • Description: extension to e164
  • Direction: Inbound
  • Field: Callee

Local dialing without area code (use break-out code 0)

  • Match Pattern: ^0([1-9][0-9]+)$
  • Replacement Pattern: ${caller_cc}${caller_ac}\1
  • Description: local to e164
  • Direction: Inbound
  • Field: Callee

National dialing (use break-out code 0 and prefix area code by 0)

  • Match Pattern: ^00([1-9][0-9]+)$
  • Replacement Pattern: ${caller_cc}\1
  • Description: national to e164
  • Direction: Inbound
  • Field: Callee

International dialing (use break-out code 0 and prefix country code by 00)

  • Match Pattern: ^000([1-9][0-9]+)$
  • Replacement Pattern: \1
  • Description: international to e164
  • Direction: Inbound
  • Field: Callee

Figure A.10. Inbound Rewrite Rule for Callee

Inbound Rewrite Rule for Callee

A.2.3. Outbound Rewrite Rules for Caller

When a call goes to a PBX subscriber, it needs to be normalized in a way that it’s call-back-able, which means that it needs to have the break-out code prefixed. We create a rule to show the calling number in international format including the break-out code. For PBX-internal calls, the caller name will be shown (this is handled by implicitly setting domain preferences accordingly, so you don’t have to worry about that in rewrite rules).

Adding a break-out code (use break-out code 0 and prefix country code by 00)

  • Match Pattern: ^([1-9][0-9]+)$
  • Replacement Pattern: 000\1
  • Description: e164 to full international
  • Direction: Outbound
  • Field: Caller

Displaying the extension in the caller number for PBX-internal calls

  • Match Pattern: ^@{callee_cloud_pbx_account_cli_list}$
  • Replacement Pattern: ${caller_cloud_pbx_ext}
  • Description: e164 to full international
  • Direction: Outbound
  • Field: Caller

Figure A.11. Outbound Rewrite Rule for Caller

Outbound Rewrite Rule for Caller

Create a new Rewrite Rule Set for each dial plan you’d like to support. You can later assign it to customer domains and even to subscribers, if a specific subscriber of a PBX customer would like to have his own dial plan.