URL rules not taking effect


(Ace2213) #1

I’m using Humhub and I’m trying to modify some URL routes via rules, but nothing seems to happen when I do. PrettyURL works fine, but additional rules seem to have no effect, not positive or negative.

This is my URL manager config:
image

I’ve tried many different combinations, based on the advice here. I’ve tried current => desired, desired => current, https:// current => https:// desired etc.

Am I missing something? Is there anything I still need to do elsewhere? Like maybe manually changing the paths in each respective view file?

The strange part is that the current URLs haven’t stopped working either, so it seems like these rules aren’t even applying.


(Softark) #2

Hi @Ace2213, welcome to the forum.

Probably you’ve misunderstood the concept. The URL rule is not something like URL Rewrite Rule in web server configuration. The basic concept of the URL rules is URL Pattern => Route Pattern, where route is controller/action or module/controller/action.


(Ace2213) #3

But isn’t that ultimately the same thing? Where /home as a URL pattern should point to the route /dashboard/views/dashboard, which is governed by the dashboard controller(s)?

Particularly when adding server names for a full path. You’re right, I really don’t understand how this is different from URL rewrites.


(Ace2213) #4

So maybe I’m crazy but I just noticed something. ([’/dashboard’]) redirected to /home (which 404’d since I have nothing set up there). Then when I changed it to (’/dashboard’), it redirected to the dashboard correctly.
image

Is this what you meant? That I triggered some kind of [controller/action/variable] which set off the URL manager?

Now I’m not sure the URL Manager can achieve what I want. Would I be better off using URL rewrite? I thought the URL Manager could change the visible URLs to make them more user-friendly, since I’ve already changed the interface names for these things and all that’s left is to change the URLs for consistency.


(Softark) #5

Right, but dashboard/views/dashboard will be translated into the route of dashboard module’s views controller’s dashboard action. Do you have it?
Please check what Routes means in Yii.(https://www.yiiframework.com/doc/guide/2.0/en/structure-controllers#routes)


(Ace2213) #6

Yeah, I don’t get the difference. And I read runtime routing too.

I get that routes can be used for much more than what I’m trying to do. My question is can they be used in this way and if so, how. If not, am I better off using URL rewrites?

To answer your question, the dashboard’s route is /dashboard.


(Softark) #7

No, it is not.
“/dashboard” may be the URL of the dashboard, but it’s not the route for it.
The route should be in the form of “controllerId/actionId” or “moduleId/controllerId/actionId”.

And would you please explain what you want to do with more specific definitions? What modules, controllers and actions do you have and what URLs do you want for them?


(Ace2213) #8

In the case of the dashboard, I want users to navigate to the dashboard by going to domain.com/home

Not just being redirected to the dashboard. I want the URL in their address bar to say domain.com/home

As another example, I have renamed Humhub’s built-in “Security” settings to “Privacy”, as I feel that’s more accurate. But the URL still reads security, as in the screenshot above. It’s more of an issue of consistency in details than anything else.

I really thought this would be fairly straightforward and a lot less complicated than it turned out to be.


(Softark) #9

I’m sorry, but I can do nothing to help you.

You have been telling only about URLs since your first post, not a bit about Routes. I have to say that you don’t understand what route is in Yii.

And I don’t know what Humhub is. Someone who knows it may help you, I hope.


(Ace2213) #10

That’s because I don’t care about routes. I’m talking about URLs because that’s my interest. I don’t understand why you keep talking about routes when I’ve explained 4 times now what I’m trying to achieve.

Humhub is clearly not relevant either but you’re clearly one of those unhelpful kinds of people so have a good day.


(Softark) #11

The URL manager does, and so do I.
If you don’t want to think about the routes, you have to forget about the URL manager.


(Ace2213) #12

I’m forgetting about Yii all together after seeing how awful, rude and unhelpful its community is. So good for you caring about routes.


(tri - Tommy Riboe) #13

I case somebody missed to read the Getting Started section of the guide, here’s at least a useful picture https://www.yiiframework.com/doc/guide/2.0/en/start-workflow#request-lifecycle.


(Softark) #14

@Ace2213, please read the following before you leave Yii (and HumHub).

I took a look at HumHub, and it seems to be a kind of CMS specialized in social networking. It is built on top of Yii, and its functionality (“dashboard”, “directory”, “space” … etc.) are implemented as modules if I’m not mistaken.

I couldn’t find much about URL management in HumHub’s documentation. It only tells you that you can enable the pretty url by configuring Yii’s URL Manager. I think it is reasonable to expect that URL Rules of Yii will work as expected also in HumHub.

So, what you wrote was this:

  1. None of the rules worked, as you say. IMO it’s because you have failed to set the route parts. They are not in valid format for route. It means that the listed URLs have no matching routes.
  2. Nonetheless, the pretty url as a whole worked as expected. It’s because enableStrictParsing is set to false. As you see in the guide:

Now, try this for testing:

'urlManager' => [
    'showScriptName' => false,
    'enablePrettyUrl' => true,
    'enableStrictParsing' => false,
    'rules' => [
        '/space/manage/privacy' => 'space/manage/security',
    ],
],

The rule above means that the URL of /space/manage/privacy should be resolved as the route of space/manage/security, i.e., ‘space’ module’s `manage’ controller’s ‘security’ action. I hope it will work as expected.

As for the other 2 rules, I can’t say anything because I don’t have enough information regarding their routes.