# Trying to redirect using rules to my custom domain

**URL:** <https://community.auth0.com/t/trying-to-redirect-using-rules-to-my-custom-domain/98846>\
**Category:** Get Help\
**Tags:** extensibility, rules-externsibility\
**Created:** [January 24, 2023, 6:19pm UTC](https://community.auth0.com/t/trying-to-redirect-using-rules-to-my-custom-domain/98846 "2023-01-24T18:19:33Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![ankitaa](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ankitaa/32/42298_2.png) [@ankitaa](https://community.auth0.com/u/ankitaa)\
**Post date:** [January 24, 2023, 6:19pm UTC](https://community.auth0.com/t/trying-to-redirect-using-rules-to-my-custom-domain/98846/1 "2023-01-24T18:19:33Z")

</div>

Hi when am trying to redirect using rules to my custom domain, and when i trigger the /continue api, I end up landing on the same custom domain instead of returning back to the auth0 rule? Can you help?

 ![image](https://global.discourse-cdn.com/auth0/original/3X/a/9/a900632e3b22ba60173822be80f28ae8933aad5c.png)

---

<div class="post-metadata">

**Author:** ![rueben.tiow](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rueben.tiow/32/11646_2.png) [@rueben.tiow](https://community.auth0.com/u/rueben.tiow)\
**Post date:** [January 24, 2023, 6:40pm UTC](https://community.auth0.com/t/trying-to-redirect-using-rules-to-my-custom-domain/98846/3 "2023-01-24T18:40:20Z")

</div>

Hi @ankitaa,

Thanks for reaching out to the Auth0 Community!

> [@ankitaa](#):
>
> when am trying to redirect using rules to my custom domain, and when i trigger the /continue api, I end up landing on the same custom domain instead of returning back to the auth0 rule? Can you help?

It sounds to me like you are encountering a redirect loop. If so, I recommend resuming the authentication flow in your Rule by checking the `context.protocol` property.

```auto
function (user, context, callback) {
    if (context.protocol === "redirect-callback") {
        // User was redirected to the /continue endpoint
    } else {
        // User is logging in directly
    }
}

```

Reference: [Redirect Users from Within Rules](https://auth0.com/docs/customize/rules/redirect-users#validate-resumed-login)

I hope this helps!

Please let me know if there’s anything else I can do to help.

Thanks,  
Rueben

---

<div class="post-metadata">

**Author:** ![ankitaa](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ankitaa/32/42298_2.png) [@ankitaa](https://community.auth0.com/u/ankitaa)\
**Post date:** [January 24, 2023, 6:56pm UTC](https://community.auth0.com/t/trying-to-redirect-using-rules-to-my-custom-domain/98846/4 "2023-01-24T18:56:00Z")

</div>

What am I suppose to add in the if and else conditions as described above?

---

<div class="post-metadata">

**Author:** ![ankitaa](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ankitaa/32/42298_2.png) [@ankitaa](https://community.auth0.com/u/ankitaa)\
**Post date:** [January 24, 2023, 6:58pm UTC](https://community.auth0.com/t/trying-to-redirect-using-rules-to-my-custom-domain/98846/5 "2023-01-24T18:58:24Z")

</div>

Can you help me out with an example, currently my continue url is [https://staging-environment.us.auth0.com/continue?state=${state}](https://staging-environment.us.auth0.com/continue?state=%24%7Bstate%7D) and my redirect url is context.redirect = {  
url: `http://localhost:3000/login?token=${token}`,  
};

---

<div class="post-metadata">

**Author:** ![ankitaa](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ankitaa/32/42298_2.png) [@ankitaa](https://community.auth0.com/u/ankitaa)\
**Post date:** [January 24, 2023, 7:04pm UTC](https://community.auth0.com/t/trying-to-redirect-using-rules-to-my-custom-domain/98846/6 "2023-01-24T19:04:26Z")

</div>

if (context.protocol === “redirect-callback”) {  
// User was redirected to the /continue endpoint  
context.redirect = {  
url: `https://staging-environment.us.auth0.com/continue`,  
};

```
} else {
      context.redirect = {
url: `http://localhost:3000/login?token=${token}`,

```

};  
}

is this something that you are suggesting?

---

<div class="post-metadata">

**Author:** ![rueben.tiow](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rueben.tiow/32/11646_2.png) [@rueben.tiow](https://community.auth0.com/u/rueben.tiow)\
**Post date:** [January 25, 2023, 7:52pm UTC](https://community.auth0.com/t/trying-to-redirect-using-rules-to-my-custom-domain/98846/7 "2023-01-25T19:52:33Z")

</div>

Hi @ankitaa,

> [@ankitaa](#):
>
> is this something that you are suggesting?

Yes, that is correct.

How does it work for you?

Thanks,  
Rueben

---

<div class="post-metadata">

**Author:** ![ankitaa](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ankitaa/32/42298_2.png) [@ankitaa](https://community.auth0.com/u/ankitaa)\
**Post date:** [January 31, 2023, 6:48am UTC](https://community.auth0.com/t/trying-to-redirect-using-rules-to-my-custom-domain/98846/8 "2023-01-31T06:48:05Z")

</div>

worked fine and solved the issue thanks

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [February 14, 2023, 6:48am UTC](https://community.auth0.com/t/trying-to-redirect-using-rules-to-my-custom-domain/98846/9 "2023-02-14T06:48:45Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
