# Redirect / for non-logged in users?

**URL:** https://meta.discourse.org/t/redirect-for-non-logged-in-users/33500
**Category:** Feature
**Created:** [20 בספטמבר,‏ 2015,‏ 5:28pm UTC](https://meta.discourse.org/t/redirect-for-non-logged-in-users/33500 "2015-09-20T17:28:33Z")
**Posts on this page:** 20
**Page:** 1

<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: [20 בספטמבר,‏ 2015,‏ 5:28pm UTC](https://meta.discourse.org/t/redirect-for-non-logged-in-users/33500/1 "2015-09-20T17:28:33Z")

</div>

Not really sure if this has been discussed before - and also not if this is more “feature request” or more “extensibility”. Since I feel this is something others might have considered, I wanted to ask you guys here: In my opinion, it would make major sense to send all anonymous traffic landing on my page directly to /categories instead of /latest.

For the registered users in my community, it makes more sense to show them what happened lately - but for the public, it’s much better to show them the structure of what’s going on. I could even imagine a (custom) profile setting for each user where they can specify where they want to land when they go to [http://example.com](http://example.com) - depending on their favourite mental structure either categories, or latest (or even unread or new or…).

I wonder if this can be easily (or not-so-easily) be achieved by a custom user script, plugin or extension of the core functionality?

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [20 בספטמבר,‏ 2015,‏ 7:35pm UTC](https://meta.discourse.org/t/redirect-for-non-logged-in-users/33500/2 "2015-09-20T19:35:36Z")

</div>

You can see how they do it at [community.imgur.com](http://community.imgur.com) note that first load is always categories, but subsequent clicks or taps on the logo send you to latest. It is an interesting compromise.

---

<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: [20 בספטמבר,‏ 2015,‏ 7:47pm UTC](https://meta.discourse.org/t/redirect-for-non-logged-in-users/33500/3 "2015-09-20T19:47:46Z")

</div>

That’s great indeed… Is there an easy way to tweak the link for the logos into https://…/latest?

---

<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: [21 בספטמבר,‏ 2015,‏ 5:24pm UTC](https://meta.discourse.org/t/redirect-for-non-logged-in-users/33500/4 "2015-09-21T17:24:52Z")

</div>

Hm… here’s how far I got:

```plaintext
<script>
  Discourse.HomeLogoComponent.reopen({
   linkUrl: function() {
       return Discourse.getURL('/latest');
   }.property(),   
  });
</script>

```

Which works pretty well, since I get this a tag on my logo:

```plaintext
<a data-auto-route="true" href="/latest">

```

… **but:** if I click on the logo image, it takes me to `Discourse.getURL('/');` (i.e. [www.example.com](http://www.example.com) instead of [www.example.com/latest](http://www.example.com/latest)) in spite of the correct href attribute?! ~~Wut??~~ Oh.

```plaintext
  click: function(e) {
    // if they want to open in a new tab, let it so
    if (e.shiftKey || e.metaKey || e.ctrlKey || e.which === 2) { return true; }

    e.preventDefault();

    DiscourseURL.routeTo('/');
    return false;
  }

```

Really? You define a property linkUrl and override click events to a hard-coded ‘/’? 😃

Trying to figure out how to import DiscourseURL now… if anyone has hints, I will be glad…

---

<div class="post-metadata">

### Author: ![riking](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/riking/32/170938_2.png) [@riking](https://meta.discourse.org/u/riking)
#### Post date: [21 בספטמבר,‏ 2015,‏ 6:49pm UTC](https://meta.discourse.org/t/redirect-for-non-logged-in-users/33500/5 "2015-09-21T18:49:03Z")

</div>

This patch should do it:

[https://github.com/discourse/discourse/pull/3799](https://github.com/discourse/discourse/pull/3799)

```plaintext
<script>
  var HomeLogoComponent = require('discourse/components/home-logo').default;
  HomeLogoComponent.reopen({
   targetUrl: function() {
       return '/latest';
   }.property(),   
  });
</script>

```

alternate form:

```plaintext
<script>
define('discourse/pre-initializers/change-home-logo', ["exports", "discourse/components/home-logo"],
function(ex, hlModule) {
var HomeLogoComponent = hlModule.default;
ex["default"] = {
  name: "change-home-logo",
  initialize: function(container) {
    HomeLogoComponent.reopen({
      targetUrl: function() {
       return '/latest';
      }.property(),
    });
  }
}});
</script>

```

---

<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: [22 בספטמבר,‏ 2015,‏ 7:35pm UTC](https://meta.discourse.org/t/redirect-for-non-logged-in-users/33500/6 "2015-09-22T19:35:04Z")

</div>

Do you know when this PR will pass? Probably the spurious Travis failure prevents further actions?

---

<div class="post-metadata">

### Author: ![riking](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/riking/32/170938_2.png) [@riking](https://meta.discourse.org/u/riking)
#### Post date: [22 בספטמבר,‏ 2015,‏ 7:52pm UTC](https://meta.discourse.org/t/redirect-for-non-logged-in-users/33500/7 "2015-09-22T19:52:05Z")

</div>

Nope, we’re doing the release right now 😉

---

<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: [22 בספטמבר,‏ 2015,‏ 7:53pm UTC](https://meta.discourse.org/t/redirect-for-non-logged-in-users/33500/8 "2015-09-22T19:53:11Z")

</div>

Okay, noticed that. Just keep on! And thanks!! 😃

---

<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: [22 בספטמבר,‏ 2015,‏ 8:24pm UTC](https://meta.discourse.org/t/redirect-for-non-logged-in-users/33500/9 "2015-09-22T20:24:00Z")

</div>

Haha I was doing an ugly hack because I want to redirect to main site when on discourse main page, this is wonderful!

```plaintext
<script type="text/javascript">

  var goToPortal = function() { 
      if (window.location.href === 'https://example.com.br/forum/') { 
          window.location = 'https://example.com.br';
      }
  };
  
  Discourse.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', goToPortal, false);
  }
});
</script>

```

---

<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: [24 בספטמבר,‏ 2015,‏ 6:17pm UTC](https://meta.discourse.org/t/redirect-for-non-logged-in-users/33500/10 "2015-09-24T18:17:27Z")

</div>

While I waited for that PR, and since I needed the functionality, I threw together this:

[https://github.com/JSey/logo-click](https://github.com/JSey/logo-click)

…I am reluctant to open a plugin topic for this, since it is so tiny… If you find it useful, enjoy.

---

<div class="post-metadata">

### Author: ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)
#### Post date: [20 בינואר,‏ 2016,‏ 1:47pm UTC](https://meta.discourse.org/t/redirect-for-non-logged-in-users/33500/11 "2016-01-20T13:47:42Z")

</div>

**FYI:** I just merged @riking’s PR 😉

---

<div class="post-metadata">

### Author: ![Yuun](https://avatars.discourse-cdn.com/v4/letter/y/977dab/32.png) [@Yuun](https://meta.discourse.org/u/Yuun)
#### Post date: [20 בינואר,‏ 2016,‏ 2:30pm UTC](https://meta.discourse.org/t/redirect-for-non-logged-in-users/33500/12 "2016-01-20T14:30:17Z")

</div>

And it works quite nicely! Thanks @riking and @JSey for your little plugin that I’ve been using up until now. 😀

---

<div class="post-metadata">

### Author: ![glynhudson](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/glynhudson/32/120597_2.png) [@glynhudson](https://meta.discourse.org/u/glynhudson)
#### Post date: [21 באפריל,‏ 2016,‏ 12:22pm UTC](https://meta.discourse.org/t/redirect-for-non-logged-in-users/33500/13 "2016-04-21T12:22:02Z")

</div>

Now that his patch has been integrated how can I implement on my site? I would like to direct logo click to /latest and make categories the first landing page to help new users.

Thanks

---

<div class="post-metadata">

### Author: ![Yuun](https://avatars.discourse-cdn.com/v4/letter/y/977dab/32.png) [@Yuun](https://meta.discourse.org/u/Yuun)
#### Post date: [21 באפריל,‏ 2016,‏ 1:25pm UTC](https://meta.discourse.org/t/redirect-for-non-logged-in-users/33500/14 "2016-04-21T13:25:17Z")

</div>

Just copy and paste riking’s script here into `</head>` in Admin → Customize → CSS/HTML to have the logo redirect to `/latest`.

> [@riking](#):
>
> ```plaintext
> <script>
> var HomeLogoComponent = require('discourse/components/home-logo').default;
> HomeLogoComponent.reopen({
> targetUrl: function() {
> return '/latest';
> }.property(),   
> });
> </script>
> 
> ```

To make categories the landing page, go to Admin → Site Settings → Basic Setup and make categories the first entry in the list for the `top menu` setting.

---

<div class="post-metadata">

### Author: ![glynhudson](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/glynhudson/32/120597_2.png) [@glynhudson](https://meta.discourse.org/u/glynhudson)
#### Post date: [21 באפריל,‏ 2016,‏ 2:23pm UTC](https://meta.discourse.org/t/redirect-for-non-logged-in-users/33500/15 "2016-04-21T14:23:09Z")

</div>

Works a treat 😃

Thanks so much for quick reply.

My new forum setup is coming along nicely  
[http://community.openenergymonitor.org](http://community.openenergymonitor.org). So much nicer than our old Durpal 6  
PHP setup [http://openenergymonitor.org/emon/forum](http://openenergymonitor.org/emon/forum)

---

<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: [26 באפריל,‏ 2016,‏ 8:16pm UTC](https://meta.discourse.org/t/redirect-for-non-logged-in-users/33500/16 "2016-04-26T20:16:09Z")

</div>

Uh - and @Yuun’s code broke again:

```
Error: Could not find module discourse/components/home-logo

```

Where did that disappear to? Did a quick recursive grep, but came up with 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: [26 באפריל,‏ 2016,‏ 8:18pm UTC](https://meta.discourse.org/t/redirect-for-non-logged-in-users/33500/17 "2016-04-26T20:18:37Z")

</div>

It’s broke because the new header.

> [@Help us test the new header code!](https://meta.discourse.org/t/help-us-test-the-new-header-code/43184):
>
> I’ve just merged another client side performance improvement for Discourse. Our site header has been re-written using the [widget code](https://meta.discourse.org/t/a-tour-of-how-the-widget-virtual-dom-code-in-discourse-works/40347) that gave us a huge performance increase within topics. The site header is present on every page and our benchmarks showed that it often took up 1/4 of the initial rendering time of a Discourse page. With the new code, it renders roughly 8x faster than before, which should be a significant improvement on android devices. Since this is a major re-write, the odds …

---

<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: [26 באפריל,‏ 2016,‏ 8:22pm UTC](https://meta.discourse.org/t/redirect-for-non-logged-in-users/33500/18 "2016-04-26T20:22:33Z")

</div>

Yup, seen that, thanks. I guess I will x-post my question there since it belongs to that new addition.

---

<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 באפריל,‏ 2016,‏ 5:19pm UTC](https://meta.discourse.org/t/redirect-for-non-logged-in-users/33500/19 "2016-04-27T17:19:02Z")

</div>

I’ve added a new widget setting to customize that url in this commit:

[https://github.com/discourse/discourse/commit/02f771e66ead3fb6e861bfa1fd41d8c65d10ab1d](https://github.com/discourse/discourse/commit/02f771e66ead3fb6e861bfa1fd41d8c65d10ab1d)

Here’s an example of how to use it via a customization:

```html
<script type="text/discourse-plugin" version="0.4">
  api.changeWidgetSetting('home-logo', 'href', '/new-url')
</script>

```

Just replace `/new-url` whatever you want the path to be and you should be good to go.

---

<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 באפריל,‏ 2016,‏ 5:34pm UTC](https://meta.discourse.org/t/redirect-for-non-logged-in-users/33500/20 "2016-04-27T17:34:36Z")

</div>

I want to change the behavior of the home logo only when users are at my home page (window.location === ‘[example.com/forum/](http://example.com/forum/)’).

Should passing a function as the third parameter work?

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