DID to extension mapping to avoid loop

Some of our customers keep dialing the DID of another phone behind the same PBX instead of extension#. This is causing loop detection by our upstream voip provider, leading to call drop. Although, we keep instructing our customers to use the extension#'s, they never get it. Is there a way to reroute calls for DID’s to their extension#'s, so that the call does not leave the PBX? Can anyone provide help on how to create this dial plan. We are using FreePBX and asterisk 1.2 on redhat. Any help would be greatly appreciated


can someone please respond? I am sure this is not the first time i am reporting this issue

Recognize your own number in the context used for interpreting calls from local users, transform it and go directly to the local extension.

David thanks for the response. Is there a pre-defined context that identifies the local numbers?. ARe you referring to from-internal? Can you please provide some more details. Really appreciate it.

Hi there is NOTHING pre defined in asterisk.

You need to add the DID to the outbound contexts and point it to the internal number.


I looked at this further. Is there any way in the dialplan to check if the destination number dialed matches either DID for the PBX or one of the inbound routes? If so, we can simply re-route the call to the ext-did-direct and ext-did subroutine.

That’s what we have been suggesting.

I tried this. Although it works for DID’s that need to be routed locally. The problem here is how do i check if the dialed number first matches the list of DID’s or Inbound Routes. I want to be able to check this before i route the call to the ext-did or ext-did-direct routine. Please note that i do not want to explicitly specify the list of DID’s and inbound routes again( avoid diplication). If i do not do this then any external number called is failing

You shouldn’t have completely specified them to Asterisk before, but if, somehow you did, we can’t guess how you’ve done it. Normally DID would only contain the variable part of the number.

If you just mean the decoding of the tail end of the number, then just use the Goto application to goto the approriate substring of the number, from the outgoing context to the DID incoming context.

David thanks for the response. I think we area really close to resolving this. Appreciate if you can take a look a this.

Not sure what you mean when DID would contain only the variable part of the #. We have different ring groups to ring based on the called DID. So we specify differnt inbound routes for each. Also, thre are some extensions that have direct DID’s. This is definitely needed.
Here is how from-internal-custom looks for the change i tried to make(basically to route externall dialed number through the ext-did-direct and ext-did routiens)


include ==> ext-did-direct
include ==> ext-did
exten => _1XXXXXXXXXX,1,noop(${EXTEN})
exten => _1XXXXXXXXXX,n,gosub(ext-did-direct,${exten},1) ; Here i want to pass control to subroutine only if the dialed number matches an entry in the list of DID’s
exten => _1XXXXXXXXXX,n,gosub(ext-did,${exten},1) ; Here i want to pass control to subroutine only if the dialed number matches an entry in the inbound route list

If i do pass control for any extenernally dialed number that does not match DID or inbound route then the routine does not return and the call fails.


any thoughts from anybody?