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, biapar, Willr, Ingo, swaiba, simon_w

UNSOLVED - Dynamic redirect based on domain, hide parent node from URL


3 Posts   1124 Views


3 March 2011 at 1:45pm (Last edited: 3 March 2011 1:49pm), Community Member, 56 Posts

Hey everyone!

It's either I am an idiot or I'm not seeing something very obvious. (probably the former :)

I am trying to do a redirect based on the domain that the request is coming. I have several domains parked. In my SiteTree I have a simple structure - a holder page on the top level, one for each domain, named after the domain without the .com/.net part.

Like this:

> Root

When a request to my default domain, the regular deep linking is applied, eg. is alright.

When a request comes from, however, I would like the url to be parsed without repeating domain, eg:

instead of

In .htaccess, I have tried:

RewriteCond %{HTTP_HOST} !www\.defaultdomain\.com [NC]
RewriteCond %{HTTP_HOST} ^www\.([A-Z,a-z,0-9,\_]*).* [NC]
RewriteCond %{REQUEST_URI} ^(.*)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* sapphire/main.php?url=%1/%2&%{QUERY_STRING} [L]

but it's not working. Then I notice the url variable in htaccess, which I assume gets processed somewhere - at which point?
Perhaps I should pass the whole thing, domain, and deep links, to the url and then work with it somewhere in SilverStripe? e.g. htaccess would send a full request to sapphire/main.php?, then I would somehow split the url variable in PHP and then display the correct page. No clue if there's a different method than Director::redirect to pull a particular Page from the SiteTree and display it without changing the actual URL.

I -have- tried Director::redirect... but that one displays the new url with the redirect. I was even able to get the appropriate page ID based on the domain, but I can't seem to get Director to just display a particular page object, but not redirect.

Hope this makes sense, I've been killing myself over this for 2+ months.


3 March 2011 at 9:48pm (Last edited: 3 March 2011 9:57pm), Community Member, 215 Posts

You do know that there is a field in the behaviour tab called "Use this page as the 'home page' for the following domains"?


4 March 2011 at 11:18am (Last edited: 5 March 2011 6:40am), Community Member, 56 Posts

Ha, in two years working with Silverstripe I never realized it did just what I needed :) Thanks a ton!


Actually, the function is not working as I would like it to. If I remove all secondary domain specific htaccess rules, the problem arises with sublinking.

E.g. I want to display which in the sitetree is actually (root)/secondarydomain/home. Using the previous link, it will show the root (root)/home. I don't want the parent page to be visible in my url for all secondary domains. To put it another way, I need a 1st-level url link to display a 2nd level page.