Page 1 of 1

Clean urls (hack)

Posted: Sat Jan 07, 2006 12:04 pm
by tsw
Clean url by default doesnt take into account the hierarchy of the links, here is a hack to have urls like "http://www.domain.tld/parent1/parent2/parentN/page.html"

in lib/misc.functions.php add

Code: Select all

 
function clean_urls($my_ID) {
  global $gCms;
  global $config;

  $thispage = $page;

  $thispage = $my_ID;


  $trail = "";
  $delimiter = "/";

#Make an array for all pages
  $allcontent = array();

#Load current content
  $onecontent = ContentManager::LoadContentFromId($thispage, false);

  if ($onecontent !== FALSE)
    {
      array_push($allcontent, $onecontent);

#Grab all parents and put them into the array as well
      while ($onecontent->ParentId() > 0)
        {
          $onecontent = ContentManager::LoadContentFromId($onecontent->ParentId(), false);
          // tdh add / modify next 5 lines
          if (isset($params['root']))
            {
              if (strtolower($onecontent->Alias()) != strtolower($params['root']))
                {
                                        array_push($allcontent, $onecontent);
                }
            }
          else
            {
              array_push($allcontent, $onecontent);
            }
        }

#Pull them one by one in reverse order to construct a breadcrumb list
      $first=1;
      while ($onecontent = array_pop($allcontent))
        {
          if($first) {
            $trail = $onecontent->getURL();
            $strip = count_chars($config["page_extension"]);
            $trail = substr($trail, 0, -5);
            $trail .= $delimiter;
            $first=0;
          } else {
            $trail .= $onecontent->MenuText() . $delimiter;
          }
        }
      $trail = substr($trail, 0, -1);
      $trail .= $config["page_extension"];
      return $trail;
    }
}
 
before ?> at the end

in modules/CSSMenu/CSSMenu.module.php edit lines

Code: Select all

                        if ($onecontent->Id() == $gCms->variables['content_id'])
                        {
                               $menu .= "<li class=\"menuactive\"><a href=\"".$onecontent->GetURL()."\"";
                        }
                        else
                        {
                               $menu .= "<li><a href=\"".$onecontent->GetURL()."\"";
                        }


to read

Code: Select all

                        if ($onecontent->Id() == $gCms->variables['content_id'])
                        {
#                               $menu .= "<li class=\"menuactive\"><a href=\"".$onecontent->GetURL()."\"";
                                $menu .= "<li class=\"menuactive\"><a href=\"".clean_urls($onecontent->Id())."\"";
                        }
                        else
                        {
#                               $menu .= "<li><a href=\"".$onecontent->GetURL()."\"";
                                $menu .= "<li><a href=\"".clean_urls($onecontent->Id())."\"";
                        }

new .htaccess file

Code: Select all

RewriteEngine On
#Rewrites anything/page.shtml as index.php?page
RewriteCond %{REQUEST_FILENAME} !-f [NC]
RewriteRule ^(.*/)?([a-zA-Z0-9\.]+)\.html$ index.php?page=$2 [QSA]
in config change
$config['page_extension'] = '.html';
$config['assume_mod_rewrite'] = true;


try it, tested with news module and it should fallback to "messyURL"  ???

thanks go to breadcrumbs, most of the function is copy paste from there  ;)

Re: Clean urls (hack)

Posted: Sun Jan 08, 2006 7:51 am
by phdm
tsw wrote: Clean url by default doesnt take into account the hierarchy of the links, here is a hack to have urls like "http://www.domain.tld/parent1/parent2/parentN/page.html"
I am just discovering CMSMS and I haven't tested this hack yet and the poblem you mention with modules. But your hack seems very interesting. From a usability point of view, such "clean URLs" seem much better than the existing one.

We could imagine that such clean URLs could be an option for CMSMS (the 2 other options would be: 1) no clean URL, 2) the existing clean URLs system).

@mitiés

Philippe (phdm)

Re: Clean urls (hack)

Posted: Fri Jan 20, 2006 3:17 pm
by j2the3rd
THIS is exactly what i'm looking for... but it doesn't seem to be playing nice...

I have a brand new fresh install, with nothing but the default content in and once I implement each of the steps here, I get 404 errors off the home page.

only about 1/2 the main links work, and none of the 2nd level pages work at all.

Clean urls were working fine with the fresh install, but I really want this type of hierarchy in the links.

Is this working with the latest release of CMSMS? Any help would be appreciated.

Re: Clean urls (hack)

Posted: Tue Apr 11, 2006 5:23 pm
by 3stripe
I've just installed CMSMS for the first time - is it safe to try using the hack above?

I'm also very keen to make the urls more (search-engine) friendly....

Cheers

Re: Clean urls (hack)

Posted: Wed Apr 12, 2006 12:49 pm
by tsw
actually that hack is kind of old and Im trying to push new way for this in future relase..

Re: Clean urls (hack)

Posted: Mon Apr 24, 2006 9:17 am
by nils73
No more need for hacks guys: 0.13beta1 is out and takes care of all these things. Congratulations, Ted! If you'd like to know how to use Clean URLs (pretty urls) when you upgrade to 0.13, please have a look here.

There are some modifications available for creating path-like URLs and furthermore modules URLs look much prettier this way. Cheers to all who made this possible.

Regards,
Nils

Re: Clean urls (hack)

Posted: Tue Apr 25, 2006 9:56 am
by 3stripe
Wow great  ;D

I was about to give up on my first attempt at using cmsms because I had no idea how to get the urls to play nice... maybe I will now...

Re: Clean urls (hack)

Posted: Tue Apr 25, 2006 1:58 pm
by tsw
0.13 will have clean urls integrated, and much better than this hack does :)

Re: Clean urls (hack)

Posted: Tue Apr 25, 2006 3:39 pm
by nils73
tsw wrote: 0.13 will have clean urls integrated, and much better than this hack does :)
That is just what I said ...  ;)

Cheers,
Nils

Re: Clean urls (hack)

Posted: Tue Apr 25, 2006 5:17 pm
by tsw
oh  :P

note to self: read more than just the latest reply!