Take the 2-minute tour ×
Craft CMS Stack Exchange is a question and answer site for administrators, end users, developers and designers for Craft CMS. It's 100% free, no registration required.

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?

share|improve this question
    
Do you mean proper redirecting? Or do you only want that news channel index template to be you home page? –  carlcs Aug 15 at 13:38
    
I want the news channel to be my homepage. If possible redirect to the latest post in the news page. –  shanti Aug 15 at 13:40
1  
"I want the news channel to be my homepage" is not that what you get with the {% redirect %} tag. No visitor would be on http://www.example.com. –  carlcs Aug 15 at 14:29

3 Answers 3

up vote 4 down vote accepted

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 %}
share|improve this answer

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!

share|improve this answer
    
Using this technique you would want to set a canonical url to the sections entry url so google didn't see duplicate content on your homepage AND the news entry page. –  jnowland Aug 18 at 9:34
    
Right. Thanks for adding this here, @jnowland! –  carlcs Aug 18 at 9:36

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.