为什么通过 clean url 查看 Drupal 自定义菜单项时会收到 403 错误?

发布于 2024-08-28 17:26:22 字数 615 浏览 4 评论 0原文

我通过在自定义模块中定义它,在我的 Drupal 6 网站中创建了一个自定义菜单项。这是一个极其简单的 MENU_NORMAL_ITEM 菜单项。菜单项定义为

/**
 * Implementation of hook_menu().
 */
function menu_test_menu() {
  $items['menu_test'] = array(
    'title' => 'Menu Test',
    'page callback' => 'menu_test_hello',
 'access callback' => TRUE,
 'type' => MENU_NORMAL_ITEM,
  );

  return $items;
}

由于我有干净的 URL,因此路径应该是 www.example.com/menu_test。该 URL 给我一个 403 错误。但是,如果我输入 www.example.com/?q=menu_test,一切正常。为什么我会收到 403 错误?该菜单项毫无用处,因为它总是尝试访问干净的 URL 路径,这应该可以工作,但由于某种原因无法工作。

感谢您的帮助!

需要明确的是...启用了干净的 URL,并且菜单注册表已重建多次。

I've created a custom menu item in my Drupal 6 website by defining it in a custom module. This is an extremely simple MENU_NORMAL_ITEM menu item. The menu item is defined as

/**
 * Implementation of hook_menu().
 */
function menu_test_menu() {
  $items['menu_test'] = array(
    'title' => 'Menu Test',
    'page callback' => 'menu_test_hello',
 'access callback' => TRUE,
 'type' => MENU_NORMAL_ITEM,
  );

  return $items;
}

Since I have clean URLs on, the path should be www.example.com/menu_test. That URL gives me a 403 error. But, if I enter www.example.com/?q=menu_test, everything works fine. Why am I getting the 403 error? The menu item is useless because it's always trying to go to the clean URL path, which should work but doesn't for some reason.

Thanks for the help!

To be clear... Clean URLs are enabled and the menu registry has been rebuilt several times.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

树深时见影 2024-09-04 17:26:22

此问题特定于示例回调页面“menu_test”中使用的路径。更改此回调路径(例如,更改为“test_menu”)可以解决该问题。这实际上是 .htaccess 文件中的重写规则的问题。部分规则查找“test”作为路径的结尾。因此,就我而言,我将无法使用任何以“test”结尾的路径。这就是我收到 403 错误的原因。

如果您遇到相同类型的问题,请检查您的重写规则是否存在类似情况。就我而言,我决定简单地避免以“测试”结束我的任何路径,这应该不会太困难。

不管怎样,谢谢你的评论!我很高兴现在已经弄清楚了。

更正:这不是重写规则...而是保护某些文件和目录的 FilesMatch 规则。

This issue is specific to that path used in the example callback page "menu_test". Changing this callback path (for example, to "test_menu") resolves the issue. This was in fact an issue with the rewrite rule in the .htaccess file. Part of the rule looks for "test" as the ending of the path. So, in my case, I won't be able to use any path that ends in "test". This is why I was getting the 403 errors.

If you experience the same type of issue, check your rewrite rule for a similar condition. In my case, I've decided to simply avoid ending any of my paths with "test", which shouldn't be too difficult.

Thanks for the comments anyways! I'm just glad it's figured out now.

CORRECTION: It's not the rewrite rule... is the FilesMatch rule that protects certain files and directories.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文