Drupal hook_url_inbound_alter 没有改变我的网址

2022-01-23 00:00:00 path php url-rewriting drupal-7

我在名为categorie"的模块中有一个实现:

I have in my module named 'categorie' a implementation of:

function categorie_url_inbound_alter(&$result, $path, $path_language) {
  if ($path == 'e') {
    $result = 'user';        
  }
}

我打算做一些更高级的事情,但我什至无法让基本的工作.

I'm planning to do something a bit more advanced but I can't even seem to get the basic one working.

通过这个实现,我希望如果用户访问 mysite.com/e,他会获得用户页面.但我得到了 404.

With this implementation I expect that if a user goes to mysite.com/e , he gets the user page. But I'm getting a 404.

在本主题中:使用模块:url_alter 和它的钩子:hook_url_outbound_alter() 他们还建议你需要实现 hook_boot() 里面什么都没有.但是我确实实现了这个钩子,这并没有改变行为.

In this topic:Using module: url_alter and it's hook: hook_url_outbound_alter() they also suggested you need to implement the hook_boot() with nothing in it. However I did implement this hook and this didn't change the behavior.

更新:我从核心安装了路径"模块,并在干净的 url 部分声明了一些 url 别名.(也许这会产生冲突?)

UPDATE: I have the "Path" module installed from core and I declared some url aliases in the clean url section. (Maybe this gives a conflict?)

UPDATE2:清理缓存也没有用.

UPDATE2: cleaning the cache didn't do the trick either.

更新3:我还尝试在 htaccess 文件中进行 url 重写.但是当 url 被重写时,它破坏了主题.(https:///drupal.stackexchange.com/questions/76475/drupal-does-rewrite-url-but-cant-load-css-themes/76493?noredirect=1#76493).所以这就是我现在尝试使用自定义模块的原因.

UPDATE3: I also tries doing the url rewriting in the htaccess file. But when the url was rewritten it destroyed the theming. (https://drupal.stackexchange.com/questions/76475/drupal-does-rewrite-url-but-cant-load-css-themes/76493?noredirect=1#76493). So that's why I'm now trying to do it with the custom module.

推荐答案

我不是 100% 确定,因为我对 drupal 也很陌生.但我认为你也需要实现 hook_url_outbound_alter .祝你好运.如果我找到更好的答案,我会发布它.

I'm not 100% sure, cause i'm also very new to drupal. But i think you need to implement hook_url_outbound_alter as well. Good luck. If i find a better answer i'll post it.

干杯

相关文章