Jump to:

23007 Posts in 11866 Topics by 2828 members

General Questions

SilverStripe Forums » General Questions » Director::redirect not working on live site

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 2042 Views
  • Dramew
    Avatar
    Community Member
    9 Posts

    Director::redirect not working on live site Link to this post

    Good Day!
    I have the following problem.
    I have

    Director::redirect('home');


    rule in Page.php and on localhost everything works fine. But on live site it just ignores this code. Why could this happen?

    And one more question: at this moment I'm trying to redirect pages from old site to new pages in SilverStripe. Old site is created with php and xml and it has links like "xslt.php?xml=pagelink" and now I want to redirect it to "pagelink" (like it is named in SilverStripe CMS). Writing in htaccess smth like

    RewriteRule ^xslt.php?xml=pagelink$ pagelink


    doesn't work. And as I said before Director::redirect doesn't work either. Maybe there is another solution for redirecting pages like "xslt.php?xml=pagelink"?

    Any help is really appreciated!
    Thanks in advance

  • Willr
    Avatar
    Forum Moderator
    5464 Posts

    Re: Director::redirect not working on live site Link to this post

    Could you post the full code?.

    One thing to note - You might want to try including a / after the url. I think it defaults to appending the value to the current URL if it doesn't have a /

    Director::redirect('home/');

  • Dramew
    Avatar
    Community Member
    9 Posts

    Re: Director::redirect not working on live site Link to this post

    So this is the code:

    class Page_Controller extends ContentController {
       public function init() {
          parent::init();   
          $url = $_SERVER['REQUEST_URI'];
          if ($url == '/xslt.php?xml=clients/faq/faq_v&language=ru') {
             Director::redirect('faq-v/', 301);
          }
       }
    }

    I also noticed one strange thing: when I try to use the address (/xslt.php?xml...), 404 page is shown (silverstripe custom 404 page), and site looks like archive site in some way. I do not know how to explain this, but it is surely not the "fresh" version of site. For example, latest news in sidebar section show only 2 items, but at the moment there should be 5 items. And when I go to any other "normal" page, the site is ok and up-to-date.

  • Willr
    Avatar
    Forum Moderator
    5464 Posts

    Re: Director::redirect not working on live site Link to this post

    One thing to note is that your 404 page is a generated html page in assets (eg assets/error-404.html) these are not generated dynamically but are generated when you publish the page in the cms.

    Its probably showing an old version of your theme since the html hasn't been updated. To update it simply republish the Page not found page.

  • Dramew
    Avatar
    Community Member
    9 Posts

    Re: Director::redirect not working on live site Link to this post

    Thank you Willr for your help!

    But what about redirecting? Does anyone have any suggestions? I want to redirect page with url address like "xslt.php?xml=pagelink" to "pagelink". That "xslt.php?xml=pagelink" page does not exist any more. And I really cannot understand how to do that. I tried making .htaccess rules and using Director::redirect with no luck.

  • Willr
    Avatar
    Forum Moderator
    5464 Posts

    Re: Director::redirect not working on live site Link to this post

    You would not use anything at the SS level IMHO, Htaccess file would be better. Just a simple rewrite rule:

    Perhaps like this (no expert, see google for reference)

    RewriteRule .*xslt.php?xml=(.*) $1 [L,R=301]

    2042 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.