Skip to content
Grav 2.0 is officially stable. Read the announcement →

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

Archive

Removing 'blog' from url

Started by Muut Archive 12 years ago · 36 replies · 1738 views
12 years ago

I'm having a hard time trying to figure out how to completely remove the word blog from all urls while (obviously) keeping all the funcionality from the pages.

For instance:
"/blog/classic-modern-architecture" should be "/classic-modern-architecture"
"/blog/page:2" should be "/page:2"
and so on...
Thanks in advance!

12 years ago

i think you'll find you have your site installed in a directory called blog. For you to have your URLs without the blog path you will need to install Grav in the root of your webroot directory rather than in a the blog subfolder.

eg public_html/ rather than in public_html/blog

12 years ago

In fact, my site is installed in a directory called 'grav-skeleton-blog-site' but I've set up my virtual hosts correctly so that I can access it using something like: myurl.local (or localhost/grav-skeleton-blog-site/, but that's not the case).

This way, when I access myurl.local or myurl.local/blog, I go to home, which is ok.
The problem is that all the other links point to a url with blog included. For example, the first blog post points to myurl.local/blog/sunshine-in-the-hills and I wished it to point to myurl.local/sunshine-in-the-hills.

The only exception are the urls generated by some plugins like pagination, and archives that point to a url without the word blog (like, myurl.local/page:2) but they result in a 403 error.and only work if I include the 'path' to blog in it, (like, myurl.local/blog/page:2).

Is there anything I can do to get this working??

Thanks once more!

👍 1
12 years ago

I did make some changes in the last week that changes how the plugins get the path to the list view. Are you all up to date with plugins and have all the changes from the latest Antimatter template updates? Knowing that will help me help you further. Cheers.

12 years ago

I'm working on a fresh blog skeleton from the site so I think everything is up to date.
I've already tried to route in apache and play with aliases and routes in grav configs with no success...

I'm trying to figure out if there's a way to achieve similar behavior of what the alias for home (user/config/system.yaml:4) does, that worked for every page in the blog.

12 years ago

That was my first try but I wasn't able to make it work properly and it only gives me 404s. I'm probably doing something wrong but I couldn't figure out what.

12 years ago

This is not a bug only specific to this user. It happens with the blog demo at:
demo.getgrav.org/blog-skeleton/
Just hover the pointer over the first post title, and you get:
demo.getgrav.org/blog-skeleton/blog/sunshine-in-the-hills
...as the link.
So, "/blog/" is included. And it shouldn't be, right?

12 years ago

if you have a folder called user/blog where you blog is located, then yes that is a feature/limitation of Grav. Basically you can alias one url as the home.

So f you set /blog as home, then that will show you the blog at http://yoursite.com, but any subpages don't know that, so they are going to have blog in their URL. If you were to change your home to something else, they would and should still have blog in their URL.

This is not a bug, it's just how the routing works.

12 years ago

So I have to create a route for every blog post to achieve that? Is this OK (from a performance standpoint, etc.)?

12 years ago

No you shouldn't have to create a route, because it shouldn't be a problem. blog posts under the blog/ folder will have blog in them, but they should work fine.

I guess it would be helpful to see a live-site to see what the actual problem is. I'm a bit confused at this point.

12 years ago

You see, from an SEO perspective, pages with URLs without the “/directory/” part used to be (I don't know if it's still the case) considered more relevant by Google than ones with a directory in it.

👍 1
12 years ago

Having all your URLs at the root of your site is actually a common misconception about SEO. As long as your URL contains an accurately named slug for the page, you will be fine.

It's much more important to have solid content, in-links, and other factors. Google, and other search engines have long been smart enough to not fall for anything that is a quick 'trick', or 'hack' that is not directly related to your content.

Trying to convince a search engine that your page is more important because its a root URL could theoretically get you penalized.

Your best bet is to focus on the quality of your content, and the clarity of your overall content structure. Then get the word out about your content via social media to try to gain links.

👍 1
12 years ago

Wow! This is great. :) For me it's #5. OK, I will keep focusing on providing great content, and having clear "slugs". :)

12 years ago

Hey rhukster and andrelima!

Thanks for all the info on the SEO subject. Unfortunately, my problem is not a matter of SEO and I do need to make Grav work without the blog 'directories' in all the urls.

I still wasn't able to do that in apache and according to what rhukster said (or to what I understood) it seems not to be possible to do this.

Is there anything I can do in order to 'solve' this feature or should I just give up?

Thanks once more!

12 years ago

@robyflc I guess i'm not clearly getting what exactly your problem is?

12 years ago

I'll quote myself:

@robyflc
For instance:
“/blog/classic-modern-architecture” should be “/classic-modern-architecture”
“/blog/page:2” should be “/page:2”
and so on…

Since I will only have the blog in my domain, I want to be able to navigate in it without having the 'directory' blog in my urls.

Using the blog skeleton as an example,

the link for the first post is:
/blog/sunshine-in-the-hills
and is should be:
/sunshine-in-the-hills

the link for the second post is:
/blog/the-urban-jungle
and it should be:
/the-urban-jungle

I hope the issue is clear now.
I just want to know if there's a correct way or a hack or anything that could led me to a desirable solution.

Thanks once more!

12 years ago

My question is why do you want to have it without the blog/ in the urls? Why is this a problem?

Unless you have these pages at the top level of your site (eg. /user/pages/sunshine-in-the-hills), they will always have the blog slug to them in the URL. This is by design to provide no-configuration-required routing.

You can use custom routes to have a list of route alias, but this is not very practical for lots of pages.

Grav is intentionally designed to be simple, and routing is a complex problem. I can see us adding more powerful routing options in the future, but other things are more important at the moment.

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1280 9 years ago
Archive · by Muut Archive, 9 years ago
2 888 9 years ago
Archive · by Muut Archive, 9 years ago
2 4016 9 years ago
Archive · by Muut Archive, 9 years ago
1 2892 9 years ago
Archive · by Muut Archive, 9 years ago
3 1076 9 years ago