We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 29013
    • 17 Posts
    I am working on a website where the client needs to utilize Personalized URLs (PURLs).

    (For example, http://mysite.com/ would take the user to the non-personalized version of the home page, while http://mysite.com/johnsmith/ would take them to a personalized version of the home page with specific information based on their user record.)

    Now, I know that this is possible through mod_rewrite (extract the name portion of the URL and pass it as a variable to the page).

    But... MODx is already using this functionality for the Friendly URLs.

    What I want to be able to do is modify the .htaccess file so that if the URL is pointing to an existing page (e.g., http://mysite.com/about/) it will then redirect to the existing page. If the URL is not pointing at an existing page, it will then go to the home page, passing the name portion of the URL to the page as a variable, which will then use the variable to pull the personalized info from the database.

    Does anyone have some advice on how this can be done?

    (My first idea was to actually utilize the Error page -- if MODx finds the name portion doesn’t exist as an existing alias, it send the user to the home page (which would be set as the default Error page), but *also* passes the name portion of the URL as a variable. Of course, this means that I wouldn’t have a proper 404 page, so if there is another way to do this, that would be awesome.) smiley

    thanks for your help,
    jason
      • 29013
      • 17 Posts
      Isn’t that kinda dangerous though?

      None of the info shown is private. And they will have no place on the site to change their info.

      The PURLs are actually going to be sent out to a client list and they will show a homepage with different offers depending their client level.

      And if the name doesn’t exist in the client list, they just get the non-personalized homepage.

      And for anyone that cares, what I’ve decided to try is to actually modify the rewrite line in the .htaccess from this:

      RewriteRule ^(.*)$ index.php?q=$1 [L,QSA,NC]

      to

      RewriteRule ^(.*)$ index.php?q=$1&usercode=$1 [L,QSA,NC]

      The only page that will actually use the variable usercode will be the homepage and I have set the Error page to be the home page.

      So, if the usercode is blank, or "home", or a usercode that doesn’t exist in the database, or a plain old error, the non-personalized homepage will be served.

      But if the usercode appears in the database... BAM -- personalized home page.

      Yeah, it means that I don’t have a separate Error page... but this isn’t a big site and every page has a link to every other page, so it’s a tradeoff.