We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 11243
    • 27 Posts
    Hi, I’ve been trying to figure this out for a while without much luck and hope someone out there can help me out...

    My MODx (0.9.6.3) site gives details of a number of holiday rental properties (in French and English) and I want each individual property to be accessed by their own unique domain eg. www.property1.com directly maps on to property1.html (friendly urls are on) page in my modx installation.

    The method that I thought would work was to point the www.property1.com domain to the top-level of my modx installation and then place a snippet on the landing page that detected the HTTP_HOST system variable and then route to the property1.html document by changing the header location:

    $propdomain = $_SERVER['HTTP_HOST'];
    switch($propdomain) {
    case "www.property1.com" :
    $whereto = 32;
    break;
    default:
    $whereto = 31;
    }
    header ("location: ".$modx->makeUrl($whereto, '', '', 'full'));


    The problem with this was that url masking is not present so the host domain had already changed to the default domain before the snippet was executed so it always came through to the default setting. I also tried to use HTTP_REFERER without any luck either.

    Would using the rewriteRule in .htaccess provide a better solution? I don’t have much experience in using this so any advice much appreciated.
      • 27330
      • 884 Posts
      not sure i’m following but can’t you simply use .htaccess rule instead of snippet?
        • 11243
        • 27 Posts
        That is what I’m thinking, but my knowledge of writing rewriteRule in .htaccess files is very limited - I don’t even know if it’s possible. If anybody can help me with it I’d be very happy!

        To recap, I have done a url redirect on the domain www.property1.com to the url where my modx install is hosted, but need it to redirect to a specific document within the site instead of the startpage of the site. Does that make sense?
          • 11243
          • 27 Posts
          Just an update to let you know the progress of this.

          I ended up pointing the individual property domains to the ip address of the server where modx was installed and the GoToProperty snippet above then worked to route through to the individual property document. smiley My only (minor) outstanding problem is that I would prefer for just the domain to show up, but using this method I get the domain name followed by the friendly url page alias. I guess that the solution for this lies in the .htaccess file but this is beyond me!

          One other minor problem I solved in working through this which may help others is that my development modx installation was in a modx subdirectory that i accessed in the form www.mydevserver.com/modx/ and I had to add a rewrite rule to my .htaccess file that I found on the forums to add the /modx subdirectory to get friendly urls to work. When I initially set up the individual property domains directly to the modx subdirectory, I got a 500 internal server error page, but removing the /modx reference to my rewriterule in the .htaccess file fixed this! HTH