Jump to:

23483 Posts in 18976 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » UNSOLVED - Dynamic redirect based on domain, hide parent node from URL

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: 1113 Views
  • KINKCreative
    Avatar
    Community Member
    56 Posts

    UNSOLVED - Dynamic redirect based on domain, hide parent node from URL Link to this post

    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
    ->Domain1
    -->SubpageA1
    -->SubpageA2
    -->...
    ->Domain2
    -->SubpageB1
    -->SubpageB2
    ...

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

    www.defaultdomain.com/domain1/subpageA1 is alright.

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

    www.domain1.com/subpageA1

    instead of

    www.domain1.com/domain1/subpageA1

    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?url=www.domain1.com/subpageA1, 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.

  • Devlin
    Avatar
    Community Member
    215 Posts

    Re: UNSOLVED - Dynamic redirect based on domain, hide parent node from URL Link to this post

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

  • KINKCreative
    Avatar
    Community Member
    56 Posts

    Re: UNSOLVED - Dynamic redirect based on domain, hide parent node from URL Link to this post

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

    EDIT:

    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 http://secondarydomain.com/home. 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.

    1113 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.