[solved] Setting the default page to something else

Currently (gitea v 1.7.5), visiting the home page can result in one of two pages being returned depending on whether the user is logged in:

  • If the user is logged in, he or she is presented with content generated from dashboard.tmpl.
  • if the user is not logged in, the content is generated from home.tmpl.

Is there a way to set the home page to something else like the explore page (explore/repos.tmpl)?

Better yet, does gitea support something like gitlab’s “Home page URL” field in their settings page?

Cheers!

Good news and bad news: gitea seems to lack builtin functionality to set the home page to any arbitrary URL at the moment. Furthermore, there doesn’t seem to be any way to redirect the home page for logged-in users without sacrificing important UI functionality (the user’s dashboard) because said functionality seems to be exposed only at the home page url. I may be wrong here, so please correct me if I am.

This throws simple unconditional redirects off the table since it will also affect logged in users.

The good news: If you just want to redirect users who aren’t logged-in to the explore page or the organizations page, you can achieve this by setting LANDING_PAGE to either explore or organizations, respectively. This option should be set under the [server] block.

Devs who want to only redirect users that are not logged-in to an arbitrary url can do so by simply adding a redirect in the home.tmpl file in your custom/templates directory (see Customizing Gitea for more information). I’ve included the contents of my edited home.tmpl file here if anyone’s interested. It redirects to the explore page, but the url can point to any other url.

Click to see home.tmpl Code
{{template "base/head" .}}
<script>window.location.replace("{{AppSubUrl}}/explore/repos")</script>
<div class="home">
    <div class="ui stackable middle very relaxed page grid">
            <div class="sixteen wide center aligned centered column">
                    <div>
                            <img class="logo" src="{{AppSubUrl}}/img/gitea-lg.png" />
                    </div>
                    <div class="hero">
                            <div style="font-size: 16pt">
                                    Welcome, please have a look <a href="{{AppSubUrl}}/explore/repos" style="color:#4183c4">around</a>!
                            </div>
                    </div>
            </div>
    </div>

</div>
{{template "base/footer" .}}

Notes:

  1. If you want to redirect to a page inside gitea, make sure you use the {{AppSubUrl}} prefix instead of naked relative links. If you don’t, links will break if you ever move gitea to a subpath.
  2. This redirect will gracefully degrade for users who disable javascript; the redirect won’t be automatic, but users wont be stranded either.

I’ll update here if I ever manage to find a more proper solution.

Cheers!

Edit 1: Edited to reflect the information provided in @oscarlo’s post bellow.

In the app.ini file you can select any of the following to be your “landing page”:

; Landing page, can be "home", "explore", or "organizations"
LANDING_PAGE = home

Have you tried this out to see if it is what you are looking for?

1 Like

I swear I’ve looked at app.ini.sample more times than I’d care to recount, but I somehow ended up missing this option every single time. It isn’t a general redirect, but it achieves what I wanted. Thank you so much for drawing attention to LANDING_PAGE !

I’ll edit my previous post to reflect the information you provided.

Once again, thank you for helping out.

1 Like