Jump to content
icreation

Processwire URLs and SEO conflicts

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?

Share this post


Link to post
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

Share this post


Link to post
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.

Share this post


Link to post
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.)

Share this post


Link to post
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

Share this post


Link to post
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.

Share this post


Link to post
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

Share this post


Link to post
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.

Share this post


Link to post
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.

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By stanoliver
      Hi! 
      The following code snippet is part of my markup simple navigation and the url_redirect (url field in the backend) just works fine when I put an special custom url into the url_redirect field.
      <?php $nav = $modules->get("MarkupSimpleNavigation"); // topnav $current = $page->rootParent(); // current root page // subnav echo $nav->render(array( 'max_levels' => 2, 'item_tpl' => '<h4><a class="g8-bar-item g8-hover-black" href="{url_redirect|url}">{title}</a></h4><hr class="sidenav">', 'collapsed' => true, ), $page, $current); ?>  In my seperated breadcrumb navigation I use the following code snippet
      <?php foreach($page->parents()->append($page) as $parent) { echo "<li><a href='{$parent->url_redirect|url}'>{$parent->title}</a></li>"; } ?> Now to the problem: In my first code snippet above the
      url_redirect|url 
      works just fine but when I try something similiar in the second code snippet
      $parent->url_redirect|url
      I produce an server error How do I have to change the second code snippet so that it works in the correct way as the first code snippet does?
    • By Mike Rockett
      Docs & Download: rockettpw/markup-sitemap
      Modules Directory: MarkupSitemap
      Composer: rockett/sitemap
      MarkupSitemap is essentially an upgrade to MarkupSitemapXML by Pete. It adds multi-language support using the built-in LanguageSupportPageNames. Where multi-language pages are available, they are added to the sitemap by means of an alternate link in that page's <url>. Support for listing images in the sitemap on a page-by-page basis and using a sitemap stylesheet are also added.
      Example when using the built-in multi-language profile:
      <url> <loc>http://domain.local/about/</loc> <lastmod>2017-08-27T16:16:32+02:00</lastmod> <xhtml:link rel="alternate" hreflang="en" href="http://domain.local/en/about/"/> <xhtml:link rel="alternate" hreflang="de" href="http://domain.local/de/uber/"/> <xhtml:link rel="alternate" hreflang="fi" href="http://domain.local/fi/tietoja/"/> </url> It also uses a locally maintained fork of a sitemap package by Matthew Davies that assists in automating the process.
      The doesn't use the same sitemap_ignore field available in MarkupSitemapXML. Rather, it renders sitemap options fields in a Page's Settings tab. One of the fields is for excluding a Page from the sitemap, and another is for excluding its children. You can assign which templates get these config fields in the module's configuration (much like you would with MarkupSEO).
      Note that the two exclusion options are mutually exclusive at this point as there may be cases where you don't want to show a parent page, but only its children. Whilst unorthodox, I'm leaving the flexibility there. (The home page cannot be excluded from the sitemap, so the applicable exclusion fields won't be available there.)
      As of December 2017, you can also exclude templates from sitemap access altogether, whilst retaining their settings if previously configured.
      Sitemap also allows you to include images for each page at the template level, and you can disable image output at the page level.
      The module allows you to set the priority on a per-page basis (it's optional and will not be included if not set).
      Lastly, a stylesheet option has also been added. You can use the default one (enabled by default), or set your own.
      Note that if the module is uninstalled, any saved data on a per-page basis is removed. The same thing happens for a specific page when it is deleted after having been trashed.
          
    • By franciccio-ITALIANO
      Hi, we can choose the "headline" and "title" and "summery" in panel page of processwire, but we can't write the "metadecriptions" and "tags".
       I can write mdescropt and tags in templates, but I've same templates for many articles... so, how I can change mdescription and tags?

      Thanks...
    • By gregory
      Hi everyone.
      I can't see the PDF uploaded via a field called "pdf".
      I get a url like this: http://localhost:8888/mywebsite/site/assets/files/1129/test.pdf%EF%BB%BF%EF%BB%BF
      Could anyone help me? Thank you.
      <?php foreach($page->case_studies as $item) { if($item->type == 'contenuto') { echo " <a class='btn btn-primary btn-sm' target='blank' href='{$item->pdf->first()->url}' role='button'>Download</a> "; } } ?>  
    • By ce90
      Hello everyone,
      hopefully this is the right place to ask and is not a duplicate question.
      I'm pretty new to processwire, so... if this question is kind of funny for some of you, you're welcome 😄 
      I have the following issue and can't find anything understandable about it. Maybe I'm searching the wrong way, but anyways.. here is my question:

      How is it possible to rewrite the URLs, that I'll get a *.php ending?
      Example:
      https://www.mysite.de/urlsegment/ -> https://www.mysite.de/urlsegment.php
      https://www.mysite.de/urlsegment/urlsegment/ -> https://www.mysite.de/urlsegment/urlsegment.php
      Because I've read a lot about "Why do you wanna do this or have that?" – here my answer for that in advance:
      I've built a processwire installation inside or around an existing website. Therefore, we want to keep the existing *.php Google entries. Sure, we could redirect via 301 Redirect, but would prefer to keep the *.php ending.
      If you have further questions, please do not hesitate to ask.
      Thank you in advance for your help.

      Best regards
      ce90
×
×
  • Create New...