# \[NEED HELP\] redirect user from subdomain

**URL:** <https://forum.dfinity.org/t/need-help-redirect-user-from-subdomain/48988>\
**Category:** Developers\
**Created:** [May 26, 2025, 4:32am UTC](https://forum.dfinity.org/t/need-help-redirect-user-from-subdomain/48988 "2025-05-26T04:32:54Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![baolongt](https://avatars.discourse-cdn.com/v4/letter/b/4491bb/32.png) [@baolongt](https://forum.dfinity.org/u/baolongt)\
**Post date:** [May 26, 2025, 4:32am UTC](https://forum.dfinity.org/t/need-help-redirect-user-from-subdomain/48988/1 "2025-05-26T04:32:54Z")

</div>

Hi I want a way redirect user from

`www.example.com` to `example.com`

How I can do this in frontend canister?

---

<div class="post-metadata">

**Author:** ![ilbert](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/ilbert/32/8717_2.png) [@ilbert](https://forum.dfinity.org/u/ilbert)\
**Post date:** [May 26, 2025, 8:39am UTC](https://forum.dfinity.org/t/need-help-redirect-user-from-subdomain/48988/2 "2025-05-26T08:39:51Z")

</div>

At the moment, it’s not possible to configure [redirects](https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/Redirections) in the [asset (aka frontend) canister](https://github.com/dfinity/sdk/tree/b74b2fa3447059f5e3e55beb57e62ce92b7cd7ba/src/canisters/frontend/ic-frontend-canister).

However, you can achieve a similar redirect functionality using JavaScript when loading the page:

```js
if (window.location.host === "www.example.com") {
    window.location.replace("https://example.com/");
}

```

> Note: this assumes that the `example.com` domain is [configured among your custom domains](https://internetcomputer.org/docs/building-apps/frontends/custom-domains/using-custom-domains) for your frontend canister

---

<div class="post-metadata">

**Author:** ![peterparker](https://avatars.discourse-cdn.com/v4/letter/p/b9bd4f/32.png) [@peterparker](https://forum.dfinity.org/u/peterparker)\
**Post date:** [May 26, 2025, 8:51am UTC](https://forum.dfinity.org/t/need-help-redirect-user-from-subdomain/48988/3 "2025-05-26T08:51:11Z")

</div>

> [@baolongt](#):
>
> Hi I want a way redirect user from…

What’s your end goal, using the same principal on both domains?

---

<div class="post-metadata">

**Author:** ![baolongt](https://avatars.discourse-cdn.com/v4/letter/b/4491bb/32.png) [@baolongt](https://forum.dfinity.org/u/baolongt)\
**Post date:** [May 26, 2025, 9:00am UTC](https://forum.dfinity.org/t/need-help-redirect-user-from-subdomain/48988/4 "2025-05-26T09:00:53Z")

</div>

Yes but we thought it is easy if we not doing anything by just redirect user from [www.example.com](http://www.example.com) to [example.com](http://example.com)

You can see Openchat did that  
`https://www.oc.app/` → `https://oc.app/` using 307 Internal Redirect

I’m not sure how to implement it in canister, I tried to setup in DNS but it never success

---

<div class="post-metadata">

**Author:** ![peterparker](https://avatars.discourse-cdn.com/v4/letter/p/b9bd4f/32.png) [@peterparker](https://forum.dfinity.org/u/peterparker)\
**Post date:** [May 26, 2025, 9:21am UTC](https://forum.dfinity.org/t/need-help-redirect-user-from-subdomain/48988/5 "2025-05-26T09:21:31Z")

</div>

I’m not sure about using a redirect, but personally, I would handle this by instructing II to use the same principal on both domains via the “alternative origin” or “derivation origin” feature as follow.

**1. Setup**

If you’re using Juno, you can simply set the authentication domain in your `juno.config` ([reference](https://juno.build/docs/reference/configuration#derivation-origin)) or through the Console UI.

If you’re setting it up manually, you’ll need to create a file in `.well-known` containing the list of alternative origins — e.g. your `www` domain. You can follow the [documentation](https://internetcomputer.org/docs/references/ii-spec/#alternative-frontend-origins) for details.

**2. Provide derivation in sign-in**

Once the setup is complete, you’ll need to update your sign-in code to include the derivation origin when logging in with II.

With Juno, you can do something like this: [https://github.com/peterpeterparker/icdraw/blob/8950c277f19bcf0d54ee6a6c020e71438ff0efc6/src/components/auth/Login.tsx#L16](https://github.com/peterpeterparker/icdraw/blob/8950c277f19bcf0d54ee6a6c020e71438ff0efc6/src/components/auth/Login.tsx#L16)

And with `agent-js`, like that: [oisy-wallet/src/frontend/src/lib/stores/auth.store.ts at c1f4bd98468098f3bfac138ad8e585f3cea27dac · dfinity/oisy-wallet · GitHub](https://github.com/dfinity/oisy-wallet/blob/c1f4bd98468098f3bfac138ad8e585f3cea27dac/src/frontend/src/lib/stores/auth.store.ts#L75)

Hope that helps.
