We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36509
    • 127 Posts
    Not sure what you mean....

    what I want to happen is this....when someone types in the domain.com in the browser, it redirects them to www.domain.com. Could you give more details on what you mean?

    thanks

    Quote from: benmarte at Nov 16, 2013, 08:02 AM
    @Jason you need to add a http_hosts_aliases Context setting to both contexts and place the value you want to use so the site responds to both www and without.

    Good luck.
      www.JBMWebDesign.com
      www.JBMAutomation.com
      • 33337
      • 3,975 Posts
      Quote from: jasonmonette at Nov 16, 2013, 10:58 AM
      Not sure what you mean....

      what I want to happen is this....when someone types in the domain.com in the browser, it redirects them to www.domain.com. Could you give more details on what you mean?

      thanks

      Quote from: benmarte at Nov 16, 2013, 08:02 AM
      @Jason you need to add a http_hosts_aliases Context setting to both contexts and place the value you want to use so the site responds to both www and without.

      Good luck.

      Please see full tutorial on this: http://www.cmstricks.com/blog/2013/05/10/contextrouter-review/
        Zaigham R - MODX Professional | Skype | Email | Twitter

        Digging the interwebs for #MODX gems and bringing it to you. modx.link
        • 3109 ☆ A M B ☆
        • 894 Posts
        Quote from: jasonmonette at Nov 16, 2013, 10:58 AM
        Not sure what you mean....

        what I want to happen is this....when someone types in the domain.com in the browser, it redirects them to www.domain.com. Could you give more details on what you mean?

        thanks

        @Jason http_host_aliases will not rewrite the domain what it will do is the site will respond to both http://sitename.com and http://www.sitename.com or any other domain name you want to use for this specific context I'm not sure how you would get url re-writes using Context Router or if it's even possible without causing issues.

        Good Luck.
          Benjamin Marte
          Interactive Media Developer
          Follow Me on Twitter | Visit my site | Learn MODX
          • 36509
          • 127 Posts
          Can I use the htacess to accomplish this? Right now both www and non www work on both sites. I just want when someone types in domain.com to the browser it will redirect them to the www.domain.com address. This prevents google from listing 2 exact same sites. This is very easy to do with just one domain, but using the context router seems to complicate things a little.

          Thanks

          Quote from: benmarte at Nov 17, 2013, 07:35 PM
          Quote from: jasonmonette at Nov 16, 2013, 10:58 AM
          Not sure what you mean....

          what I want to happen is this....when someone types in the domain.com in the browser, it redirects them to www.domain.com. Could you give more details on what you mean?

          thanks

          @Jason http_host_aliases will not rewrite the domain what it will do is the site will respond to both http://sitename.com and http://www.sitename.com or any other domain name you want to use for this specific context I'm not sure how you would get url re-writes using Context Router or if it's even possible without causing issues.

          Good Luck.
            www.JBMWebDesign.com
            www.JBMAutomation.com
            • 27405
            • 15 Posts
            Before I came across this thread, I struggled with getting context routing for domains to work. The solution I came up with was to edit the index.php file in the root directory of the MODx install.

            I replaced the lines:
            /* Initialize the default 'web' context */
            $modx->initialize('web');
            

            with:
            /* start context mapping */
            $webDomain = $_SERVER['HTTP_HOST'];
            
            if ($webDomain == 'domain1.ext') {
                    // if the http_host corresponds to domain1.ext, switch to the context you want to for that domain
                    $modx->initialize('Context1Name');
            } else if ($webDomain == 'domain2.ext') {
                    // if the http_host corresponds to domain2.ext, switch to the context you want to for that domain
                    $modx->initialize('Context2Name');
            } else {
                    // fallback, go to the main context
                    $modx->initialize('web');
            }
            /* end context mapping */

            Seems to route fine, then ensuring that the context has the context settings (site_name, base_url, error_page, http_host, site_start, site_url, default_template) configured.

            Everything seems to work well and does not add the load of having to process anything extra in MODx, now I don't know if I will later run into problems with this method or not.

            1. Perhaps @Zaigham or someone could clarify, should I remove this method and use the ContextRouter instead?

            2. Also, I am having a problem with my template for the non-web contexts where the [[++site_name]] value pulls the Site Name from the web context instead of the initialized context. Any ideas here?

            3. Will using this method cause me problems with snippets/extras/add-ons going forward?
            [ed. note: siteleas last edited this post 12 years, 11 months ago.]
              • 3109 ☆ A M B ☆
              • 894 Posts
              @siteleas I recommend you either use the Context Router method or the manual method if you start mixing the two you will certainly run into issues with plugins not working on any context that is not web.

              I recommend you stick to using Context Router since I can assure you most plugins if not all will work across any context and you won't have any issues getting any Context Settings like you are currently experiencing.

              Good luck.
                Benjamin Marte
                Interactive Media Developer
                Follow Me on Twitter | Visit my site | Learn MODX
                • 25803 ☆ A M B ☆
                • 721 Posts
                @siteleas. This is essentially a core hack as well, so when you update MODX the index.php file will be updated and your modifications will be obliterated. It's best to use ContextRouter or the gateway method.
                  • 27405
                  • 15 Posts
                  Okay, so I transferred over to the ContextRouter plugin and removed the custom index.php that I created. The site seems to be working basically the same as with my custom index.php, so I am glad that it is routing properly using the ContextRouter plugin.

                  The trouble is that I am not getting the current context's site_name when I use [[++site_name]] in the active template for the new context. Rather, I get the site_name for the web context.

                  Could someone please diagnose this for me?

                  Here are the context settings:

                  site_name
                  	
                  Site Name
                  	
                  Title information for the non-web domain
                  
                  	
                  Base URL
                  	
                  base_url
                  	
                  /
                  
                  	
                  Error Page
                  	
                  error_page
                  	
                  16
                  
                  	
                  HTTP Host
                  	
                  http_host
                  	
                  non-web-domain.ca
                  
                  	
                  Site Start
                  	
                  site_start
                  	
                  15
                   
                  	
                  Site URL
                  	
                  site_url
                  	
                  http://non-web-domain.ca/


                  Here is the applicable section from the template [[$head]]:

                  <title>[[*longtitle:default=`[[*pagetitle]]`]] - [[++site_name]]</title>


                  As I said [[++site_name]] pulls the site name for the web context even when the template being used is applied to resources located in non-web contexts.
                    • 3109 ☆ A M B ☆
                    • 894 Posts
                    @siteleas Did you clear your cache after setting the value for the site_name?

                    Does it work when you put:
                    [[++site_name]]
                    


                    In the content area and not in a chunk or output modifier.
                      Benjamin Marte
                      Interactive Media Developer
                      Follow Me on Twitter | Visit my site | Learn MODX
                      • 40762
                      • 54 Posts
                      Hey guys, I seem to be having the same problem.

                      I am on host gator using cPanel to park my domains

                      with contextRouter I get this

                      [ContextRouter] You may have conflicting http_host definitions. Overwriting context web with EvacDisplays for host www.evacdisplays.com

                      any way going nuts about this if someone has insight thanks mark
                        Marc-Andre Audet