# Redirect / for non-logged in users?

**URL:** https://meta.discourse.org/t/redirect-for-non-logged-in-users/33500
**Category:** Feature
**Created:** [20 Setembro , 2015 17:28 UTC](https://meta.discourse.org/t/redirect-for-non-logged-in-users/33500 "2015-09-20T17:28:33Z")
**Posts on this page:** 14
**Page:** 2

<div class="post-metadata">

### Author: ![eviltrout](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/eviltrout/32/5275_2.png) [@eviltrout](https://meta.discourse.org/u/eviltrout)
#### Post date: [27 Abril , 2016 17:35 UTC](https://meta.discourse.org/t/redirect-for-non-logged-in-users/33500/21 "2016-04-27T17:35:26Z")

</div>

Hmmm, how did you do that before? I thought targetUrl was just a parameter?

---

<div class="post-metadata">

### Author: ![JSey](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jsey/32/3540_2.png) [@JSey](https://meta.discourse.org/u/JSey)
#### Post date: [27 Abril , 2016 17:51 UTC](https://meta.discourse.org/t/redirect-for-non-logged-in-users/33500/22 "2016-04-27T17:51:51Z")

</div>

Thanks a lot Robin - looks great. Only that the snippet you posted just gives me this error:

```
TypeError: Attempted to assign to readonly property.

```

or, on Chrome:

```
Uncaught TypeError: Cannot set property 'href' of undefined

```

…and makes the whole header disappear.

I guess I’m just missing something here?

---

<div class="post-metadata">

### Author: ![eviltrout](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/eviltrout/32/5275_2.png) [@eviltrout](https://meta.discourse.org/u/eviltrout)
#### Post date: [27 Abril , 2016 17:55 UTC](https://meta.discourse.org/t/redirect-for-non-logged-in-users/33500/23 "2016-04-27T17:55:55Z")

</div>

Did you get the latest master first? I tried it locally and it worked fine.

---

<div class="post-metadata">

### Author: ![JSey](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jsey/32/3540_2.png) [@JSey](https://meta.discourse.org/u/JSey)
#### Post date: [27 Abril , 2016 17:56 UTC](https://meta.discourse.org/t/redirect-for-non-logged-in-users/33500/24 "2016-04-27T17:56:57Z")

</div>

That’s the first thing I did before trying it! Is there a special section where I have to put the script code?

---

<div class="post-metadata">

### Author: ![eviltrout](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/eviltrout/32/5275_2.png) [@eviltrout](https://meta.discourse.org/u/eviltrout)
#### Post date: [27 Abril , 2016 18:01 UTC](https://meta.discourse.org/t/redirect-for-non-logged-in-users/33500/25 "2016-04-27T18:01:46Z")

</div>

Aha it seems the `tests-passed` branch failed to build due to a failing test. I’m fixing it now.

edit: fixed the test. Give it 15-20 mins and it should have a new version for you.

---

<div class="post-metadata">

### Author: ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)
#### Post date: [27 Abril , 2016 18:11 UTC](https://meta.discourse.org/t/redirect-for-non-logged-in-users/33500/26 "2016-04-27T18:11:05Z")

</div>

Sorry, this was done in a hurry 😆

```js
  window.goToPortal = function() { 
      if (window.location.href === 'https://example.com.br/forum/') { 
          window.location = 'https://example.com.br';
      }
  };

  var HeaderView = require('discourse/views/header').default

  HeaderView.reopen({
    didInsertElement : function(){
      this._super();
      Ember.run.scheduleOnce('afterRender', this, this.afterRenderEvent);
    },
    afterRenderEvent : function(){
      var logo = $('img#site-logo.logo-big').parent()[0];
    
      logo.addEventListener('click', window.goToPortal, false);
    }
  });

```

Can you help me @eviltrout ?

---

<div class="post-metadata">

### Author: ![JSey](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jsey/32/3540_2.png) [@JSey](https://meta.discourse.org/u/JSey)
#### Post date: [27 Abril , 2016 19:25 UTC](https://meta.discourse.org/t/redirect-for-non-logged-in-users/33500/27 "2016-04-27T19:25:10Z")

</div>

Like a charm. Thanks!

---

<div class="post-metadata">

### Author: ![eviltrout](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/eviltrout/32/5275_2.png) [@eviltrout](https://meta.discourse.org/u/eviltrout)
#### Post date: [29 Abril , 2016 16:41 UTC](https://meta.discourse.org/t/redirect-for-non-logged-in-users/33500/28 "2016-04-29T16:41:49Z")

</div>

Hmmm that is a little complicated to establish in the new settings. Does adding that event work in the case where the url is not `https://example.com.br/forum/` ? It seems the click handler would do nothing.

---

<div class="post-metadata">

### Author: ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)
#### Post date: [29 Abril , 2016 17:03 UTC](https://meta.discourse.org/t/redirect-for-non-logged-in-users/33500/29 "2016-04-29T17:03:19Z")

</div>

> [@eviltrout](#):
>
> It seems the click handler would do nothing.

Yes, when the user isn’t at the forum home, I want the normal behavior (scroll up / go back to home).

Only when we are already at the forum home, I want to go back to my Portal home.

---

<div class="post-metadata">

### Author: ![eviltrout](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/eviltrout/32/5275_2.png) [@eviltrout](https://meta.discourse.org/u/eviltrout)
#### Post date: [29 Abril , 2016 17:28 UTC](https://meta.discourse.org/t/redirect-for-non-logged-in-users/33500/30 "2016-04-29T17:28:06Z")

</div>

It’s quite tricky to do what you’re asking, because once an event is handled from the logo it prevents default.

I’ve added the ability for the `href` setting to be a function. Whatever value you return will be the destination when the user clicks the logo:

[https://github.com/discourse/discourse/commit/1ac6dd194d811d4bb5609562dc52176ce2bdc34f](https://github.com/discourse/discourse/commit/1ac6dd194d811d4bb5609562dc52176ce2bdc34f)

---

<div class="post-metadata">

### Author: ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)
#### Post date: [9 Maio , 2016 23:10 UTC](https://meta.discourse.org/t/redirect-for-non-logged-in-users/33500/31 "2016-05-09T23:10:32Z")

</div>

Should this work?

```html
<script type="text/discourse-plugin" version="0.4">
  api.changeWidgetSetting('home-logo', 'href', function() { 
          return 'https://example.com.br';
  });
</script>

```

EDIT:

Setting it to ‘/another/page’ when using Discourse under ‘/forum’ also breaks :sadpanda:.

---

<div class="post-metadata">

### Author: ![eviltrout](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/eviltrout/32/5275_2.png) [@eviltrout](https://meta.discourse.org/u/eviltrout)
#### Post date: [10 Maio , 2016 14:42 UTC](https://meta.discourse.org/t/redirect-for-non-logged-in-users/33500/32 "2016-05-10T14:42:46Z")

</div>

This should fix it:

[https://github.com/discourse/discourse/commit/4875fe1c3ea3865f4f37fe71fc8358c8c6341a07](https://github.com/discourse/discourse/commit/4875fe1c3ea3865f4f37fe71fc8358c8c6341a07)

---

<div class="post-metadata">

### Author: ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)
#### Post date: [10 Maio , 2016 14:47 UTC](https://meta.discourse.org/t/redirect-for-non-logged-in-users/33500/33 "2016-05-10T14:47:03Z")

</div>

I’ll test this later today! Thanks! ❤

---

<div class="post-metadata">

### Author: ![chapoi](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/chapoi/32/537252_2.png) [@chapoi](https://meta.discourse.org/u/chapoi)
#### Post date: [4 Dezembro , 2025 11:37 UTC](https://meta.discourse.org/t/redirect-for-non-logged-in-users/33500/34 "2025-12-04T11:37:00Z")

</div>



[Previous page](https://meta.discourse.org/t/redirect-for-non-logged-in-users/33500.md?page=1)
