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.

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

How can I deny users from directly accessing a page?

Go to End

3 Posts   1653 Views


Community Member, 36 Posts

5 April 2011 at 12:24pm

Edited: 05/04/2011 12:26pm

Most of the pages in the module I am building inherit from a single master page which contains common functions that all my pages share. I need to be able to access those functions from the rest of the pages with URL's like this (this is especially important for jquery):

To do that i used:

Director::addRules(100, array(
	'masterpage' => 'masterpage_Controller',

But this also means users can type in this:

And navigate directly to my master page which shows a blank page without any content. It would be great if this page returned a 404 error instead or redirected people to the mainpage

I don't want to put in any code in the master page that could do that, as it would also affect all the other pages (I.E: if I placed ContentController::httpError(404) in there, then all my pages would return a 404)

Is there some way to tell silverstripe "don't let anyone go to this specific URL"?


Community Member, 16 Posts

7 April 2011 at 3:13am

If the page is in your site tree you can simply change the page type to redirector page and send it to where ever you like.

You could also set a redirect in the init() method of the controller and redirect based on the request url.


Community Member, 36 Posts

7 April 2011 at 9:52am

If I set the page up as a redirector page will I still be able to navigate to and run that function? Or will it redirect anyone who tries to run the masterpage functions?

Also I already tried putting Director::redirect() in the init() method of the master page, but that has the adverse affect of making ALL of my pages redirect the user because they all extend from the master!