Removing 'blog' from url

I’m looking for a tool to create a blog for a client and it’s his demand (to which I completely agree) that since the only thing in his domain will be a blog, it would be senseless to have ‘blog’ in all urls.

I’ve already checked the custom routes but that wouldn’t be practical at all for lots of pages (unless I could configure it in the page itself).

At first, I thought you were using slim for routing and tried to make a route using its wildcards buti it seems that slim is only used by monolog and the debug bar. Is that correct??

Could you point me out where should I check if I decided to change routing myself?

Thanks again!

By the way, besides the aesthetic point of view, the idea is to have another blog migrated from wordpress to a new plataform as soon as this is ready and, in this case, having ‘blog’ in the url would not only be ugly but would also break everything.

Cheers!

It’s handled in Pages->dispatch() . Currently it just does a simple lookup for the appropriate path in the site.routes configuration setting. If more sophisticated routing was added, it would have to be there.

If you come up with a solid solution, and submit a pull request, i’de be more than happy to accept/merge it.

Thanks a lot, man! I’m still far from having a solid solution but I’m about to finish a quick (and ugly) hack that will help me put my client’s blog online ASAP.
But there’s still a problem with the plugins. In the paginations, for example (but it’s the same for achives and tags): out of the box, the links point to ‘/page:2’ which is the url I want to have but it returns a 403 error. To make it work, I have to manually navigate to ‘/blog/page:2’, which is undesired (for me).

I actually have a simple alias solution, please let me know if it works for you:

basically replace your Pages.php dispatch() function with this one:

    public function dispatch($url, $all = false)
    {
        // Fetch page if there's a defined route to it.
        $page = isset($this->routes[$url]) ? $this->get($this->routes[$url]) : null;

        // If the page cannot be reached, look into site wide routes.
        if (!$all && (!$page || !$page->routable())) {
            /** @var Config $config */
            $config = $this->grav['config'];

            if ($route = $config->get("site.routes.{$url}")) {
                $page = $this->dispatch($route, $all);
            } else {
                // Try looking for wildcards
                foreach ($config->get("site.routes") as $alias => $route) { 
                    $match = rtrim($alias, '*');
                    if (strpos($alias, '*') !== false && strpos($url, $match) !== false) {
                        $wildcard_url = str_replace('*', str_replace($match, '', $url), $route);
                        $page = isset($this->routes[$wildcard_url]) ? $this->get($this->routes[$wildcard_url]) : null;
                        if ($page) {
                            return $page;
                        }
                    }
                }
            }
        }

        return $page;
    }

Then you can use aliases like this in your site.yaml:

routes:
    /something/else: /blog/sample-32
    /another/one/here: /blog/sample-3
    /*: /blog/*
    /another/*: /blog/*

it’s not sophisticated routing but does provide some simple wildcard capabilities without too much overhead.

if the page is not found, it tries the wildcard routes looping over each in turn trying to find a page that exists. It will obviously match the first option that is successful.

Wow, man! Very nice and simple implementation of wildcard routing! I just made a few tests here and everything seems to work except for the plugins pages… It seems to me that they never reach index.php so they can’t be routed but I still didn’t have the time to dig into it.
Thanks a ton!

BTW this is rolled into Grav 0.9.8 that was released today.

I’ve updated my blog and it works like a charm.
Thanks a lot!

everything seems to work except for the plugins pages…
It seems to me that they never reach index.php so they
can’t be routed but I still didn’t have the time to dig into it.

So, with Grav 0.9.8 this “plugins pages” issue is solved too?

I want to use this wildcard routing feature too, for some of the reasons stated above by @robyflc, and for shorter URLs for emails and Twitter.

@andrelima, I found out that the plugins page issue isn’t a grav issue but a bug in windows apache (https://issues.apache.org/bugzilla/show_bug.cgi?id=41441).
I’m still setting up my production server but I believe everything will be ok with it
If you’re not using windows for production, I guess it won’t be a problem after all.
After my domain finishes propagating, I post any updates on the matter here…

Thanks, @robyflc. Yes, I’m on a Linux server. You know, I’m trying the wildcard routing feature, but it’s not working… What did you add to “user/config/site.yaml” for it?

Here’s my “user/config/site.yaml” file:

title: One Spiritual

author:
  name: Andre Lima

taxonomies: [category,tag,featured]

metadata:
  author: Andre Lima

routes:
  /*: "/blog/*"

What am I doing wrong?

I think its just a matter of ".
Mine is like this:

routes:
  /*: /blog/*
---

How strange, this new feature is not working for me… And, yes, I’ve tried with or without quotes.

Another thing, this is not needed anymore:

blog:
  route: ''

…right?

…And is the

home:
  alias: '/blog'

in “user/config/system.yaml” still correct?

blog: route: is no longer used by the last couple of releases of Antimatter. The base_url is calculated based on the current page. This means its more flexible if you move or rename the folder. However you guys are trying to do something pretty specialized, so you may want to hardcode or set the base_url (which is used by the plugins/sidebar) to a specific url.

OK, I’ve decided to keep it simple and just let the “/blog/” be. :wink:

blog: route: is no longer used by the last couple of releases of Antimatter.

Can you guys please announce these theme changes on the Grav blog? I am using my own theme, not the Antimatter theme. And I’m probably not alone…

Thank you so much! :slight_smile: