Jump to content

Processwire URLs and SEO conflicts


icreation
 Share

Recommended Posts

I'd be grateful if anyone has a solution to the following issue.

By default Processwire builds its urls like this:

www.domain.com/pagenameparent/pagenamechild

On the surface this seems excellent for SEO but has been causing us a few issues. Let me explain.

In a responsive environment a drop-down menu like below must activate on touch/click. And, the top level is NOT a page. (Obvious, when you consider that you cannot 'click' to this link with your finger).

See this example.

Below you will see that ABOUT US  is a top level menu with children. Is this arrangement on a Bootstrap menu ABOUT US cannot be clicked as it could be on a tablet. Therefore, ABOUT US is not a page. 

 

post-847-0-44771500-1419843928_thumb.jpg

Let's take the first child as an example. WHO WE ARE, would have its url structure built by Processwire like this:

www.domain.com/about-us/who-we-are/

2 problems here:

  1. If we create breadcrumb navigation then ABOUT US becomes a link to a page that should not exist.
  2. /about-us/ on its own creates issues with SEO. In a complex system trying to exclude these from searches and sitemaps is a a real issue.

What would solve the problem is the ability to rewrite the url structure. It would be preferable to write the example url as

www.domain.com/who-we-are/

Can this be done without having to change any core code?

Link to comment
Share on other sites

Can this be done without having to change any core code?

Sure, though the approach depends a lot on your needs. Are your top menu items always placeholders for grouping pages or can some of then be actual pages, how deep or complicated will your site hierarchy be and does the top menu have to reflect that somehow, etc.

Assuming that this is a very simple setup (no real pages in top menu at all), one approach would be creating top menu structure somewhere else (as pages), and adding a "top menu parent" Page field to pages. If a page has this field filled, it'll be displayed under said top menu item:

- Home
  - Who we are
  - About us
  - History
  - Values
  - Meet the Cashmaster  Team
  - ...
  - Topmenu
    - About Us
    - About You
    - ...

You'll need to write your own code to create markup for the top menu, and probably side menu (if you use one), but that's just about it. Something like this should work:

echo "<ul>";
foreach ($pages->find('template=top-menu-parent, sort=sort') as $parent) {
    if (!$parent->numChildren(true)) continue;
    echo "<li>{$parent->title}<ul>";
    foreach ($parent->children as $child) {
        echo "<li><a href='{$child->url}'>{$child->title}</a></li>";
    }
    echo "</ul></li>";
}
echo "</ul>";

Anyway, this is just a very crude and basic example, so if your needs are more complicated than that, there are other approaches that may make more sense. Path/URL rewriting might be one option, etc. In any case most likely you'll never need to change any core code ;)

  • Like 3
Link to comment
Share on other sites

Thanks for your reply. Usually we do have more complex needs and your answer has enabled me to research a bit more into this post -https://processwire.com/talk/topic/1799-routes-and-rewriting-urls/ 

We see this often when trying to output breadcrumbs accurately. Let me investigate this solution and report back to close the forum post with an answer for my needs hopefully.

Link to comment
Share on other sites

What happens if you don't have a site "about-us" but you have it in your url and a user tries to access it directly? I guess a 404 or a redirect? You could create "about us" as a page using a template which has no equivalent template file in the "templates" folder so it would throw a 404 if you try to access it. Or you could create the assigned template file and use $session->redirect();. In both cases I would recommend you to create "about us" as a real parent page. (It's also easier to understand the page structure in the backend than).

(Btw: On this site (http://sgym.de/) I'm using the redirect method.)

Link to comment
Share on other sites

you could create redirect to the first child to avoid 404 errors and problems with the breadcrumb thing!

look here:

https://processwire.com/talk/topic/15-how-do-i-create-a-page-that-redirects-to-its-first-child/

and here:

https://processwire.com/talk/topic/7027-making-a-child-page-the-main-page/

so the pagetree is logical - the links are working and the /about-us/ page makes no errors or deadends....

regards mr-fan

  • Like 1
Link to comment
Share on other sites

Here is another discussion on this topic. I think having some sort of "structuring item" for the backend page tree would be great. 

This could propably be done with an extension. I would write one if i had the time atm... but I don't. But as there (quite often) is a need for this from us I will talk to my boss if we can give this to ryan as a "sponsored" extension.

Link to comment
Share on other sites

I mostly use a empty template with just a redirect. One could even use a template with a simple pagefield to choose the page to redirect to. This way it's one reusable template with one small php file to it. This is easier than trying to emulate a site all over the whole website.

  • Like 1
Link to comment
Share on other sites

Don't lose site of the fact that in the case of the problem that I have posed the PAGE TREE cannot be changed. The reason is the page hierarchy of the pages must be intuitive to a non-technical client using the Processwire interface. Creating any kind of redirect does not get round the problem of breadcrumbs or SEO.

The simple request is merely to change (somehow)

www.domain.com/firstpage/secondpage

to

www.domain.com/secondpage

That is the only solution that will work.

Link to comment
Share on other sites

Why not using a template for this?

Pretty simple: you would create an url slug where it isn't needed/wanted (see the linked post).

And (as stated above) redirects would add too much complexity. It's just about structuring things for editors.

Link to comment
Share on other sites

www.domain.com/firstpage/secondpage

to

www.domain.com/secondpage

Sry I thought you wanted it the other way around. You could do this by using urlSegments in the template of the homepage.

$segment = $sanitizer->pageName($input->urlSegment1);
$page = $pages->get("parent=/about-us/, name=$segment");
if($page->id){
  echo $page->render();
}

This will show /about-us/values under /values. What you can't change is the output of $page->url as it's a mathod not a variable. So you can't use it to link to those sites.

Link to comment
Share on other sites

 Share

×
×
  • Create New...