如何删除 SilverStripe 4 中其他供应商模块添加的路由?

How to remove routes added by other vendormodules in SilverStripe 4?

我已经安装了 SilverStripe 4 的博客模块,但不想要它提供的所有不同路由。

我想删除 "profile"、"archive" 和 "tag" 路由。这些路由由模块的 BlogController class.

定义

我如何确保将这些替换为 HTTP 404 响应?

your_module_folder/_config/config.yml_if 你指出它应该被处理 After blog 模块并且你定义了那些它应该覆盖它们的路由:

---
name: your_module
After:
  - 'blog/*'
---
SilverStripe\Control\Director:
  rules:
    'profile/': 'MyCustomController'
    'archive/': 'MyCustomController'
    'tag/': 'MyCustomController'

请查看routing documentation

控制器应该只有一个操作会引发 404 http 错误。

use SilverStripe\Control\Director;
use SilverStripe\View\Requirements;

class MyCustomController extends Controller {

    private static $allowed_actions = ['index'];

    public function index(HTTPRequest $request) {
        return $this->httpError(404, "Not Found");
    }
}