Jump to content

Redirect database landing page to a record


Meddysong

Recommended Posts

Posted

I really like how if you visit https://invisioncommunity.com/4guides, you're automatically redirected to a specific article, https://invisioncommunity.com/4guides/welcome/invision-community-r7/

But how is it done? Is it just nothing more straightforward than a .htaccess redirect? If so, fine, I can do that myself. But I'm curious about whether it's achieved otherwise, say by a line of code on the page itself. If it is, what would such code look like?

Posted

For a listing template, you can just take the first record URL (if there is one) in the loop and forward there. 
{{\IPS\Output::i()->redirect($row->url(), '', 302);}}
That way, it is always automatic. 
Not sure if their index page uses something similar or a hardcoded forwarding. 

Posted
7 hours ago, opentype said:

Not sure if their index page uses something similar or a hardcoded forwarding. 

A mixture of both has worked for me on the index page:

{{\IPS\Output::i()->redirect('welcome', '', 302);}}

That redirects to the category with the slug welcome and your code in the listing template ensures that the first article in that category is displayed.

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...