How to Create Redirect Pages Using Page Attributes

Permalink 3 users found helpful
If you ever need a page in your site to redirect to a certain URL or subpage you do the following:

1. Add a "Text" page attribute with the handle "redirect_to_url"

2. Add the following code to your themes template(s) in an appropriate place:
if ($redirectURL = $c->getCollectionAttributeValue('redirect_to_url')) {
   if ($redirectURL != '') {   
      Header( "HTTP/1.1 301 Moved Permanently" ); 
      Header( "Location: " . $redirectURL ); 

Now whenever you need a page to redirect to another URL you can simply add the new attribute and enter the destination URL.

View Replies:
ScottC replied on at Permalink Reply
you'd want to create a page_type controller for your underlying page's page_type, then
function on_start(){
if(Page::getCurrentPage()->getAttribute('redirect_to_url') $this->redirect('/redirect-landing-page'); or i think redirect_external('external redirect text')

Something really really close to that, to make sure your page_type controller is hooking up with your page's page_type make sure just to put in your on_start method print "running";

Check out the concrete5 developer documentation to see the right directory structure to make the view away of a page_type controller.
altitudems replied on at Permalink Reply
I'm not sure I understand what you are saying.

I see you are suggesting using the page event on_start but I'm not what you are getting at.
Cristi replied on at Permalink Reply
Hi there,

I am having this problem as well. Can you please be more specific on this matter?
Where exactly do we need to place the .php code, and, how would the link would look like for redirect? Absolute or relative?

Already tried out and didn't worked at all. Can we see please some screen shots ? WOuld be nice.

Renaudbb replied on at Permalink Reply
Thanks, this works perfectly.

Cristi :

- I added the piece of code in the header.php of the INC section in my template. Just after another <?php> section.

- I created the TEXT attribute through "pages & themes" / "attributes" section in the dashboard.

- if you want to redirect a page to another one on your site, put /new-page/ in the text attribute of the first page. => it will be redirected to http://yoursite/new-page/
nerdess replied on at Permalink Reply
just use the free add-on "Page Auto Redirect", it worked fine for me :)