Home page » Blog » SEO friendly URLs in HumHub

SEO friendly URLs in HumHub

You are running a HumHub network and want to optimize it for search engines?

Then understandable URLs are a crucial basis.

In this article you learn how to configure those in HumHub.

PrettyURLs

First of all check if PrettyURLs are activated. Your Dashboard should be found at domain.com/dashboard . If your browser shows domain.com/index.php?r=dashboard%2Fdashboard instead, PrettyURLs are not yet active.

Activate Pretty URLs

In newer HumHub versions after the installation you find a file called env.example

You can copy or rename it to .env

Open the file and change the lines

#--- Pretty URLs (Recommended)
#HUMHUB_CONFIG__COMPONENTS__URL_MANAGER__SHOW_SCRIPT_NAME=false
#HUMHUB_CONFIG__COMPONENTS__URL_MANAGER__ENABLE_PRETTY_URL=true

to:

#--- Pretty URLs (Recommended)
HUMHUB_CONFIG__COMPONENTS__URL_MANAGER__SHOW_SCRIPT_NAME=false
HUMHUB_CONFIG__COMPONENTS__URL_MANAGER__ENABLE_PRETTY_URL=true

So the hashtags at the beginning of line 2 and 3 are removed. (The first line is just a comment to have a good orientation in the file.)

If you can now open pages, you don't have to do anything further.

If your web server is Apache like on most common servers, you have to copy another file, the file .htaccess.dist

Copy this file or rename it to .htaccess (with the dot at the beginning).

In most cases this is enough to enable PrettyURLs. But every server configuration can be different. In case it didn't work look into the official HumHub Documentation about PrettyURLs and get help in the HumHub Community.

Optimize URLs

Even with activated PrettyURLs unfortunately not all HumHub URLs are SEO friendly. For example the URLs for the single view of posts and other contents. They e. g. look like this community.humhub.com/s/announcements/post/post/view?id=17422

To optimize the URLs is a task for advanced users, but I'll explain everything step by step.

Attention: Before you make any changes to your configuration file, copy the file so you can restore it in case of a mistake. Even a small typo can make your network unreachable.

The configuration file can be found at protected/config/common.php

Now add rules like in the following example for the Legal Tools module:

  • pattern is the new URL (without domain), so what should comes after domain.com/ .
  • route is the old URL (without domain), so what comes after domain.com/ and before the question mark.
  • defaults are the parameters of the old URL that come after the question mark. ?pageKey=imprint becomes ['pageKey' => 'imprint'].

So now instead of e.g. domain.com/legal/page/view?pageKey=imprint the short, well-readable URL domain.com/imprint will be shown.

Optimize URLs of Posts

If singel posts are particularly important for Search Engine Optimization you can configure readable URLs for them.

With the SEO module

Activate the SEO mode in the settings of the SEO module.

Open the single view of the post. To go there open the dropdown menu of a post, click "Permalink" and then "Open". Now you see the single view of the post.

Now click the button "Edit SEO" to open the SEO settings of the current page.

There you see a code snippet that you can add the configuration file. Use the following example as guide and the example above.

Attention: Before you make any changes to your configuration file, copy the file so you can restore it in case of a mistake. Even a small typo can make your network unreachable.

<?php
return [
    'components' => [
        'urlManager' => [
            'rules' => [
                [
                    'pattern' => 'my-post',
                    'route' => 'post/post/view',
                    'defaults' => ['id' => '5', 'cguid' => '864e917d-a839-4733-b239-89468d63b0e6']
                ],
            ],
        ],
    ],
];
  • my-post: new URL
  • post/post/view: old URL without parameters
  • 5: ID of the post
  • 864e917d-a839-4733-b239-89468d63b0e6: GUID of the space in which the post was published.

Leave a Comment

Your email address will not be published. Required fields are marked *

Shopping Basket
Scroll to Top