Redirection from localhost:3000 to localhost:3000/home

1.5k Views Asked by At

I have issues to understand the Apostrophe CMS. I follow the tutorial in [Creating your first project][1] and stop just before the point where things become interesting.

I can open my basic/default website with localhost:3000 and see the content of the home.html file, while localhost:3000/home throws an error. Here is my home.html file:

my-project\lib\modules\apostrophe-pages\views\pages\home.html


{#
This is an example home page template. It inherits and extends a layout template
that lives in lib/modules/apostrophe-templates/views/outerLayout.html
#}

 {% extends data.outerLayout %}

 {% block title %}{{ super() }} | Home{% endblock %}

{% block main %}
<div class="main-content">
 <h3>Hello world!
  {% if not data.user %}
    <a class="login-link" href="/login">Login</a>
  {% endif %}
</h3>
<p>This is a very barebones Apostrophe project. 
 Now, get to work and make a real website!</p>
</div>  
{% endblock %}
  • Where is the setting that apostrophe knows that home.html is the first (start) page which needs to be rendered?
  • And vice versa, I have seen a page when I call localhost:3000, apostrophe redirects directly to localhost:3000/home. Where is the setting that I tell apostrophe move automatically from localhost:3000 to localhost:3000/home?
1

There are 1 best solutions below

1
On BEST ANSWER

I'm the lead developer of Apostrophe at P'unk Avenue.

Generally speaking, on a web site the "home page" is so named because it appears at "/" (at the root), not because it actually has the URL "/home". In Apostrophe the home page is always at "/" (*). Generally speaking this looks more professional than giving the home page a longer URL.

But if you really need "/home" to work for some reason, for instance to support legacy URLs and keep links from breaking, you can use the apostrophe-redirects module to add a redirect from /home and any other legacy URLs.

You could also make a subpage of the home page and set its slug to /home, but that would be a strange solution because it wouldn't be... well, it wouldn't be the home page. (The slug of the home page itself cannot be edited in Apostrophe.)

A ticket could be opened to add the ability for the home page to not have the slug "/", and for "/" to redirect to whatever the slug of the home page has been set to, but a good case would have to be made for why the feature is necessary.

(*) The only exception would be when using the apostrophe-workflow module, in which case you might have separate home pages for different languages, but you still wouldn't have "/home" in this scenario.