We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 17930
    • 81 Posts
    Title was: Can a Context act like a container for the main domain? (didn’t seem to fit the last few questions in last few posts.)

    I would like to use a Context (or something similar) to organize/contain my files on the root directory.

    The reason being, that I work for a company that we create landing pages for business owners on the root directory.

    site.com/area_name

    I would like to not have a huge long resource tree. Is there a way to use a Context to contain these landing pages, but still be able to access them from site.com/area_name?


    Currently I’m using .htaccess and a folder called ’areas’ to contain the landing pages, but the only way I could figure out how to do it limits the urls to where they need the underscore. I really don’t like needing the underscore in the url.

    Here is the .htaccess line:
    RewriteRule ^([^/]+)_([^/]+) /areas/$1_$2.html [NC]



    A Context would be nice because then I could create editing/viewing permissions easier (I think) if I wanted to do that in the future.

    Or if there is a way to nest a Context with in another, but still access the files from the root. site.com/area_name

    I have created a Context and used it as a subdomain. So I understand that much.
      • 17930
      • 81 Posts
      After getting thinking about it, I think what I would like to be able to do is assign a Resource to a category and then collapse the category, much like the Snippets, Templates, etc. The categories don’t change where and how to access the Elements when you call them, but it just organizes them. There could even be a switch/button to show the Resource tree organized with categories with in the folders or to show it organized without categories, which is the way it is now.

      That way, if I wanted to, I could group Resources together and then view them all or view only the ones that were in certain categories. They would still be in their directory folders but also organized by category within their folder in a category container (which could be a transparent looking file folder image?).

      This would almost be like the way some programs work that you use to program. In some programming programs, you can click on the left side of the window and it collapses all the code inside that element.

      So this:
      <div>
      <p>
      Blah
      </p>
      </div>


      Would turn into:
      <div>...</div>


      But the code is still there, but just hiding. Kind of like how Firebug works.

      I don’t know though. I’m just trying to figure out a way to fix what I need done. If any one has suggestions on how to do this, that would be greatly appreciated.

      It’s just that some folders get really long and being able to group items in a folder without having to actually move them into a sub-folder would be nice (I think).
        • 17930
        • 81 Posts
        I love talking to myself.

        I asked this on another site to try to get to where I need to be. I think I understand contexts a little better and they won’t work for what I need. So I’m stuck in the folder, which is fine, but I can’t get this work on modx 2.0.7. It works on modx 1.0.4.



        Okay, so I have this working on my old version of my CMS, modx 1.0.4. But I want to get it working for the new version, modx 2.0.7, which I can’t get it working.


        This is what I had:
        RewriteRule ^([^/]+)_([^/]+) /area/$1_$2.html [NC]
        
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        #RewriteRule Pattern Substitution [OptionalFlags]
        
        RewriteRule ^(.*)\.html index.php?q=$1 [L,QSA] 


        I’m not sure why it won’t work on the new CMS, but it may have something to do with this line of code breaking the new CMS or at least mine.
        RewriteRule ^(.*)\.html index.php?q=$1 [L,QSA] 


        So they replaced it with:
        RewriteRule ^(.*)$ index.php?q=$1 [L,QSA] 



        This is what I want to do:
        - rewrite any request that doesn’t have a period ’.’ after www.domain.com/ to /area/file.html
        - not be required to have to have the underscore ’_’ (the reason I was required to do that is because it was the only way I could get it working the way I wanted to in order to shorten the url)


        I’ve tried lots of things, but can’t figure it out. I’m using MODX 2.0.7.
          • 17930
          • 81 Posts
          Is this something I should be doing in .htaccess or should I be doing this with a plugin? Here is the other forum I’m asking this on.

          http://www.webmasterworld.com/apache/4276838.htm
            • 17930
            • 81 Posts
            I got this to work in the Evo .htaccess, but I can’t get it to work in the Revo .htaccess.

            RewriteRule ^([^/.]+)$ /test/$1 [NC]


            I don’t mean to be a nuisance, it’s just that either something isn’t working right, or I’m trying to do something in Revo that can’t be done. Should I do this in a plugin?
              • 27330
              • 884 Posts
              I think you went a bit too far for what you trying to do if I understand you correctly.
              If you are using friendly urls and have friendly alias path set to yes than your urls will show the ’directory’ they in.
              check in the system setting the settings you have for Friendly URLs.
              and for your problem, are you sure your .htaccess is working at all?
              try adding some dummy text to beginning of file and see if the server throws an error.
                • 17930
                • 81 Posts
                Sinbad, thank you, I do appreciate your help.

                I put some random text in the .htaccess and it did throw an Internal Server Error.

                I checked the Friendly Alias Path and it is set to Yes.

                But the thing is, I want all the other files to work just like they do. /here/there/file.html to show as /here/there/file.html.

                It is just these certain files that I have in this certain folder that I want/need to shorten the url. This is the way I have it working in Evo, it is just that the .htaccess isn’t working the same way in Revo.

                Here is the .htaccess I have in Revo:
                RewriteEngine On
                RewriteBase /
                
                RewriteCond %{HTTP_HOST} .
                RewriteCond %{HTTP_HOST} ^domain\.com [NC]
                RewriteRule (.*) http://www.domain.com/$1 [R=301,L]
                
                RewriteRule ^([^/.]+)$ /test/$1.html [NC]
                
                RewriteCond %{REQUEST_FILENAME} !-f
                RewriteCond %{REQUEST_FILENAME} !-d
                RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
                  • 17930
                  • 81 Posts
                  Okay, so I’m not going for the record for the number of personal posts to other user posts ratio.

                  But I’m finally done with this problem I had.


                  I created a plugin. Now I can use folders somewhat like categories. Also, it may be easier to allow access for users to see/edit only specific folders, I’ll see.


                  - OnWebPageInit

                  <?php
                  // should recognize shortened urls as valid if they are in specific directories that are in the top level - ie. only folder/FILE.html
                  // this way you can use folders somewhat like categories
                  
                  // however, if you want the extension to be part of the shortened url, then take out anything to do with $extensions
                  // meaning if you want to shorten the url to www.domain.com/FILE.html, instead of www.domain.com/FILE
                  
                  // this also doesn't work well with wayfinder because wayfinder will put in the 'folder' and the extension
                  // but the files can still be accessed through folder/FILE.html,
                  // just be careful because the search engines will see it as duplicate content
                  
                  // will NOT work for  folder/subfolder/FILE.html
                  
                  $alias = null;
                  $alias_check = array();
                  $folder_id = array(5);// the resource id(s) of the folder(s) that can be omitted from the url
                  $extensions = array('.html', '/');// the extensions to check
                  
                  if($modx->_systemConfig['friendly_alias_urls'] == 1) 
                  {
                  	if ($modx->event->name == 'OnWebPageInit')
                  	{
                  		foreach($folder_id as $key => $value)
                  		{
                  			$folder_id = $value;
                  			
                  			$folder = $modx->getObject('modResource', array('id' => $folder_id) );
                  			$alias_folder = $folder->get('alias') .'/';
                  			
                  			// gets the FILE - the url the user is trying to request
                  			$alias = $modx->request->getResourceIdentifier('alias');
                  			
                  			foreach($extensions as $key => $value)
                  			{
                  				$alias_ext = $value;
                  				
                  				// builds the url to check
                  				$alias_check[] = $alias_folder . $alias . $alias_ext;
                  			}
                  		}
                  	}
                  }
                  
                  if($alias)
                  {
                  	foreach($alias_check as $key => $value)
                  	{
                  		$alias_path = $value;
                  		$holder = $modx->aliasMap;
                  		
                  		// if 'folder/FILE.html' IS in the alias map or 'site tree'
                  		if( isset( $holder[ $alias_path ] ) )
                  		{
                  			// get the id of folder/FILE.html
                  			$actualDocId = $holder[ $alias_path ];
                  			
                  			// this will allow people to enter www.domain.com/FILE 
                  			// and instead of being a 404 error
                  			// it will load www.domain.com/folder/FILE.html
                  			// but show as www.domain.com/FILE
                  			
                  			// load the resource, but leave url as www.domain.com/FILE
                  			$modx->sendForward($actualDocId);
                  			
                  			exit();
                  		}
                  		
                  		// check as case-insensitive, just in case user didn't capitilize url correctly
                  		$alias_path = strtolower( $alias_path );
                  		$holder = array_change_key_case( $holder );
                  		
                  		// if 'folder/file.html' IS in the alias map or 'site tree'
                  		// then send error 404 because they didn't type url correctly - ie. case-sensative
                  		if( isset( $holder[ $alias_path ] ) )
                  		{
                  			// creates the http://www.domain.com/
                  			$holder_2 = $modx->placeholders;
                  			$base_url = $holder_2['site_url'];
                  			
                  			// get the id of folder/FILE.html
                  			$actualDocId = $holder[ $alias_path ];
                  			
                  			// get the resource, and then build the shortened url to forward to
                  			$file = $modx->getObject('modResource', array('id' => $actualDocId) );
                  			$url = $base_url . $file->get('alias');
                  			$modx->sendRedirect($url, 0, '', 'HTTP/1.0 301 Moved Permanently');
                  			
                  			exit();
                  		}
                  	}
                  }



                  Enjoy anyone.