Demystifying Barebone URLs: A Clear Explanation

Barebone takes a unique approach to URLs, aiming for both search engine and human friendliness compared to the traditional query string approach. Instead of using a complex string of parameters after a question mark, Barebone utilizes a segment-based structure.

example.com/news/article/show/my_article

Breaking Down the Segments:

Following the Model-View-Controller (MVC) approach, each segment in a Barebone URL has a specific purpose:

  1. Application: The very first segment identifies the specific application within your Barebone project. In this example, it's "news".
  2. Controller: The second segment defines the controller class that will handle the request. Here, it's "article".
  3. Action: The third segment represents the action function (or method) within the controller responsible for the task. In this instance, it's "show".
  4. Arguments: Any remaining segments are considered arguments that will be passed to the action function. Here, "my_article" is an argument, potentially representing a specific article ID.

Benefits of this approach:

  • Clarity for Humans: The URL structure is easier to understand and remember for users, making navigation more intuitive.
  • Search Engine Optimization (SEO): Segment-based URLs are generally considered friendlier for search engines, potentially improving discoverability.

Additional Points to Note:

  • Barebone allows for an unlimited number of arguments after the action segment, providing flexibility in passing data to controller functions trough a URL.
  • This is a simplified explanation, and additional rules or configurations might be present in specific Barebone implementations.
  • URI Segments with Name-Value Pairs: Barebone also supports named segments using the name:value format. This can improve readability and maintainability of your URLs.

example.com/application/controller/action/pageid:12/menuid:3/

Here, "pageid" and "menuid" are named arguments, with their corresponding values being "12" and "3" respectively.

In essence, Barebone URLs offer a clear and user-friendly way to structure requests, making your web application more accessible and SEO-friendly.

<?php
function indexAction( $args = [] ){
    echo $args[1]; // from the $args array passed into the action
    echo $this->segment(1); // from a Controller
    echo $this->request->getSegment(1); // from the Request object
    $segment = $this->request->getSegment(1); // from the Request object
    if($segment instanceOf URISegment){
        //$this->debug($segment);
        echo $segment->getName();
        echo $segment->getValue();
    }

    $same_segment = $this->request->getSegmentByName('seg2'); // from the Request object by name
    if($segment instanceOf URISegment){
        //$this->debug($segment);
        echo $segment->getName();
        echo $segment->getValue();
    }
}

Avoiding Search Engine Confusion:

Using Canonical Tags in Barebone

Ever wondered why your Barebone project might have duplicate URLs? The answer lies in its structure. This unique setup can sometimes lead to search engines encountering duplicate content, potentially impacting how your pages are indexed and displayed.

Fear not! Barebone addresses this automatically by adding a canonical meta tag to your layout.

What is a canonical tag?

This special bit of code acts as a signal to search engines, indicating the original and authoritative version of a page when similar content exists across multiple URLs.

Why is this important?

  • Prevents confusion: By clearly specifying the original URL, search engines can avoid mistakenly treating different URLs as duplicates, ensuring your content is indexed correctly.
  • Improves SEO: Directing search engines to the preferred URL can potentially improve your Search Engine Optimization (SEO), boosting your website's visibility and ranking for relevant searches.

Remember:

  • Barebone handles this process automatically, so you don't need to worry about manually adding the code yourself.
  • Understanding the concept of canonical tags and their role in SEO empowers you to navigate the world of website optimization with more confidence.

So, rest assured, Barebone takes care of the technical details, allowing you to focus on creating fantastic content!