We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 17851
    • 213 Posts
    I have a client with site abc.com and I’ve got "Use friendly alias path" enabled, so that I’ll get a url like: abc.com/products/widget/...
    The widget is a popular brand that they’d like to setup a distinct URL for: widget.com
    I’m trying to use mod_rewrite in such a way that widget.com points to abc.com/products/widget. Here’s what I’ve got in .htaccess:
    RewriteEngine On
    RewriteCond %{HTTP_HOST} .
    RewriteCond %{HTTP_HOST} !(www\.)?abc\.com [NC]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?q=$1 [QSA]
    
    RewriteCond %{REQUEST_FILENAME} !-f [OR]
    RewriteCond %{REQUEST_FILENAME} index.php
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(index\.(html?|php)|products\widget)?(.*)$ index.php?q=/products/widget/$3 [L,QSA]
    


    This gets me most of the way there, but when I goto widget.com, I get the correct page but with "widget.com/products/widget/" in the URL instead of just "widget.com". I did a brief read of SEO Strict snippet. Is this something that snippet would help with? Or is SEO strict functionality included in 0.9.6? Any other ideas?
      Mark Macatee
      President
      Power 10 Solutions
      http://www.power10solutions.com
      • 21257 MODX Staff
      • 730 Posts
      The Strict URL plugin is not going to help you with that because you are trying to rewrite URLs outside of the standard way that MODx works with URLs.
      It’s always going to want the URL in the address bar to be /products/widget because, strictly, that’s what it should be according to the document tree and the fact that you have friendly alias paths enabled. However disabling friendly alias paths also won’t allow Strict URLs to help you. I don’t think you can use that plugin, and recommend disabling it.
      It seems to me that you should have a rewrite rule that rewrites requests for widget.com to the exact MODx document id.. something like (let’s assume your widget document id is 53..)
      RewriteCond %{HTTP_HOST} (www\.)?widget\.com
      RewriteRule ^(.*)$ index.php?q=53 [L]
      

      That also assumes that you only want to use widget.com or www.widget.com for that one MODx page, or else you’ll have to make the rules more specific.
      Also, on your widget page, even though the user will be seeing it in their address bar as widget.com, MODx is still running configured for abc.com, and any links (if you’re using Ditto or Wayfinder or Breadcrumbs etc) will still be links into the abc.com site.
        Mike Schell
        Lead Developer, MODX Cloud
        Email: [email protected]
        GitHub: https://github.com/netProphET/
        Twitter: @mkschell
        • 17851
        • 213 Posts
        Thanks for the info on SEO Strict. I actually don’t have it installed...was just verifying that it would/wouldn’t help me out.

        re:url’s in doc...yeah, I’ve got that covered with a custom plugin that calls "preg_replace" to do two things in the document content during OnWebPagePrerender:
        1. strip the relative path from all urls: "/products/widget"
        2. replace abc.com with widget.com

        Seems to work pretty well so far. The main problem I’m having right now relates to having a FirstChildRedirect as the primary doc, so that when I goto widget.com, the correct document is called but the url changed to widget.com/products/widget/info.html instead of just widget.com/info.html. I’ll go check that out, but do you know of a quick way of handling that in FirstChildRedirect? For example, can I modify the displayed URL after a FirstChildRedirect?
          Mark Macatee
          President
          Power 10 Solutions
          http://www.power10solutions.com
          • 21257 MODX Staff
          • 730 Posts
          I could be wrong, but I think it would take a couple of rules in conjunction to accomplish that.
          This is just a guess.. I’ve never tried this before:
          RewriteCond %{HTTP_HOST} (www\.)?widget\.com
          RewriteRule ^(.*)$ info.html [R,C]
          RewriteRule ^info\.html$ index.php?q=53 [P,L]
          

          I’m not entirely sure about that [C] flag ("Chain"). I want URLs for widget.com to be Redirected to info.html, then I want the next rule to catch info.html and invisibly get the content from index.php?q=53 (thus the [P] "Proxy" flag.
          If "C" doesn’t work, you might try "N" ("Next").
          Good luck.
            Mike Schell
            Lead Developer, MODX Cloud
            Email: [email protected]
            GitHub: https://github.com/netProphET/
            Twitter: @mkschell