Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

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

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

Director::redirect not working on live site


Go to End


6 Posts   3489 Views

Avatar
Dramew

Community Member, 9 Posts

9 March 2010 at 9:43pm

Edited: 09/03/2010 9:45pm

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

Avatar
Willr

Forum Moderator, 5523 Posts

10 March 2010 at 5:32pm

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/');

Avatar
Dramew

Community Member, 9 Posts

13 March 2010 at 2:29am

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.

Avatar
Willr

Forum Moderator, 5523 Posts

13 March 2010 at 11:25am

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.

Avatar
Dramew

Community Member, 9 Posts

15 March 2010 at 8:04am

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.

Avatar
Willr

Forum Moderator, 5523 Posts

5 May 2011 at 7:00pm

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]