Jump to content

how to get all urls directly off root with html extension


OllieMackJames
 Share

Recommended Posts

I have a current site in modx evolution with many many indexed pages, all directly under the root and with an .html extension.

I would like to still port this site to processwire, but because I have many first page results in the search engines, due to the structure and probably backlinks as well, it is imperative to keep all pages directly under the root with the html extension.

I already found out about the setting to take out the trailing slash and that I can just name the page with .html at the end, but what I do not understand yet, is how to go about the part to remove parts of the url, I found the code from here: http://processwire.com/talk/topic/5448-remove-parents-from-url/?hl=rewriting#entry52656

/**
 * This hook modifies the default behavior of the Page::path function (and thereby Page::url)
 *
 * The primary purpose is to redefine blog posts to be accessed at a URL off the root level
 * rather than under /posts/ (where they actually live). 
 *
 */
wire()->addHookBefore('Page::path', function($event) {
  $page = $event->object;
  if($page->template == 'post') {
    // ensure that pages with template 'post' live off the root rather than '/posts/'
    $event->replace = true;
    $event->return = "/$page->name/";
  }
});

But can not get this to work, where should I put this?

Thanks!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...