When users enter http://www.example.com I would like to redirect them to the http://www.example.com/news template.
How could I achieve this?
When users enter http://www.example.com I would like to redirect them to the http://www.example.com/news template.
How could I achieve this?
You can do this with Craft’s {% redirect %} tag. Just put this in your /index.html template:
{% redirect 'news' %}
If you want to redirect to the latest entry in your News section, as you mentioned in the comments above, just fetch the entry first:
{% set latestNews = craft.entries.section('news').order('postDate desc').first() %}
{% redirect latestNews.url %}
If you want one of your channel entries to be the homepage, simply include the channel entries' template to your home page index.html
:
{# Set the `entry` variable manually #}
{% set entry = craft.entries.section('news').first() %}
{# Load the channel entry template #}
{% include "news/_entry" %}
With this setup, your visitors would actually be on your homepage's URL http://www.example.com
instead of never really landing there.
You'd possibly even confuse some visitors, if they get redirected to http://www.example.com/news/my-not-so-very-long-news-title
straight away and they might search for your proper home page?!
I'm not sure at all, but I can imagine a regularly changing redirect (each time you add a new news post you'd also have a new home URL!) could also by problematic for SEO rankings. Please correct me if I'm wrong with that!
EDIT:
This answer was given when it wasn't yet clear that @shanti wants one of the channel entries to become the home page. The following is only relevant, if you want a channel's index page to be available under http://www.example.com
.
.
I'd recommend you to add a single section to your configuration as the entry for your channel's index. In this single's settings you select the template you currently use and you have a checkbox to make this single entry your home page!
Another idea would be to use one structure section for all singular content pages (e.g. about, contact, etc.) and all your channel index pages (e.g. projects, news). There are other interesting Q/As here on Stack Exchange on that topic. If you're going that way, have a look at the answers on "Add home page to a structure?"
If you simply want to redirect the visitors to http://www.example.com/news
, there's a {% redirect %}
tag available for such redirects.
Another approach if you simply want to use a channel as your homepage (rather than redirecting) is to just make your homepage extend the channel's index template. For example, set your homepage template to:
{% extends "news/index" %}
...and the News channel will appear on your homepage.
{% redirect %}
tag. No visitor would be onhttp://www.example.com
.