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're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

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

Making a page accessable from multiple URLs

Go to End

3 Posts   828 Views


Community Member, 545 Posts

26 November 2012 at 7:17am

I need to make a pagetype accessable from multiple URLs. Am I better off trying overload the Director to search anotehr field or to create a custom redirector page that doesn't show up in the sitetree and create it in the onBEforeWrite of the original page? Background: its for a real estate site. I'd like propoerties to be available from the address and the MLS number

The rederector is an easier solution to code, but I'm wondering about perfomance since it essentially doubles teh size of my site tree.


Forum Moderator, 5523 Posts

2 December 2012 at 5:41pm

You could create a custom handleAction function on your HomePage_Controller to do the lookup for a matching Property, return a redirect rather than the normal handleAction and fall back to parent::handleAction(). Can't find too many examples in the docs but you should checkout Controller.php and ContentControlller.php's handleAction to get an idea of what you need

HomePage_Controller {

function handleAction($request) {
check to see if $Action matches a listing..
if matches redirect ($this->redirect(..)


Community Member, 545 Posts

10 December 2012 at 4:58pm

Overlaoding handleAction and handleRequest doesn't seem to give access to the $URLSegment Section.
I started digging back thorugh the controller and found that if I ReWrite the getNestedController in ModelAsAdmin it works how I need (not ideal) and just extending ModelAdmin and overriding it with Director::addRules seems to kill the hompage redirect

here is my getNestedController to give you an idea of what I'm trying to acheive.

public function getNestedController() {
		$request = $this->request;
		if(!$URLSegment = $request->param('URLSegment')) {
			throw new Exception('ModelAsController->getNestedController(): was not passed a URLSegment value.');
		// Find page by link, regardless of current locale settings
		if(class_exists('Translatable')) Translatable::disable_locale_filter();
		$listing = DataObject::get_one('Listing', "MLS = '$URLSegment'");
			$URLSegment = $listing->URLSegment;
		$sitetree = DataObject::get_one(
				'"URLSegment" = \'%s\' %s', 
				(SiteTree::nested_urls() ? 'AND "ParentID" = 0' : null)
		if(class_exists('Translatable')) Translatable::enable_locale_filter();
		if(!$sitetree) {
			// If a root page has been renamed, redirect to the new location.
			// See ContentController->handleRequest() for similiar logic.
			$redirect = self::find_old_page($URLSegment);
			if($redirect) {
				$params = $request->getVars();
				if(isset($params['url'])) unset($params['url']);
				$this->response = new SS_HTTPResponse();
						// Needs to be in separate join links to avoid urlencoding
						($params) ? '?' . http_build_query($params) : null
				return $this->response;
			if($response = ErrorPage::response_for(404)) {
				return $response;
			} else {
				$this->httpError(404, 'The requested page could not be found.');
		// Enforce current locale setting to the loaded SiteTree object
		if(class_exists('Translatable') && $sitetree->Locale) Translatable::set_current_locale($sitetree->Locale);
		if(isset($_REQUEST['debug'])) {
			Debug::message("Using record #$sitetree->ID of type $sitetree->class with link {$sitetree->Link()}");
		return self::controller_for($sitetree, $this->request->param('Action'));