簡體   English   中英

在 Shopware6 中重定向 url 沒有 '/'

[英]Redirect url withouth '/' in Shopware6

如何在url重定向到帶有斜杠的頁面中沒有'/'的情況下以專業的方式解決。 當前 Shopware 6 在鏈接不帶斜線時出現 404 錯誤。 我在 kernel 事件中解決了一次 - 通過檢查 uri 路徑進行響應,如果 uri 沒有它,則添加斜線。 我不知道這是不是正確的方法。

這是我試圖解決問題的代碼部分:

if (str_ends_with($path, '/') && !$event->getResponse() instanceof StorefrontResponse) {
    $response = new RedirectResponse($this->router->generate('frontend.home.page'), 301);
    $event->setResponse($response); 

   return;  
}

KernelEvents::REQUEST應該適合。 因為您可能會轉發請求。

但是,還有一個很棒的插件可以解決斜線問題: https://store.shopware.com/en/kielc49617690410/trailing-slash-redirect.html

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM