Cannot redirect to an empty URL

Created on 16 May 2024, 6 months ago
Updated 20 August 2024, 3 months ago

For some reason, one of my pages is getting this error:

The website encountered an unexpected error. Try again later.

InvalidArgumentException: Cannot redirect to an empty URL. in Symfony\Component\HttpFoundation\RedirectResponse->setTargetUrl() (line 68 of /vendor/symfony/http-foundation/RedirectResponse.php).
Drupal\Component\HttpFoundation\SecuredRedirectResponse->setTargetUrl() (Line: 39)
Symfony\Component\HttpFoundation\RedirectResponse->__construct() (Line: 26)
Drupal\Core\Routing\TrustedRedirectResponse->__construct() (Line: 166)
Drupal\redirect\EventSubscriber\RedirectRequestSubscriber->onKernelRequestCheckRedirect()
call_user_func() (Line: 111)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch() (Line: 157)
Symfony\Component\HttpKernel\HttpKernel->handleRaw() (Line: 76)
Symfony\Component\HttpKernel\HttpKernel->handle() (Line: 58)
Drupal\Core\StackMiddleware\Session->handle() (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle() (Line: 28)
Drupal\Core\StackMiddleware\ContentLength->handle() (Line: 32)
Drupal\big_pipe\StackMiddleware\ContentLength->handle() (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass() (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle() (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle() (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle() (Line: 36)
Drupal\Core\StackMiddleware\AjaxPageState->handle() (Line: 51)
Drupal\Core\StackMiddleware\StackedHttpKernel->handle() (Line: 704)
Drupal\Core\DrupalKernel->handle() (Line: 19)

I deleted the one redirect that showed up in node edit. I tried disabling "Enforce clean and canonical URLs" and cleared cache, but the page still has the white screen error.

🐛 Bug report
Status

Needs review

Version

1.9

Component

Code

Created by

🇺🇸United States joshuasosa

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @joshuasosa
  • 🇺🇸United States joshuasosa

    Attached is a patch that just checks if the resulting URL is empty before performing the redirect response. This fixes the issue for me, but it could also be good to figure out how to prevent the issue from happening in the first place.

  • 🇮🇳India ameymudras

    @joshuasosa thanks for the patch. I checked the code and looks like we are fixing the symptom rather than the root cause. The redirect URL is a required field and hence its absolute URL shouldn't be empty in the first place. It would be helpful if you could provide exact testing steps here

  • 🇺🇸United States joshuasosa

    Thanks for reviewing! I'm not currently sure about steps to reproduce. The issue I encountered might stem from a migration from D7 to D9/10.

  • 🇺🇸United States ngreenup

    I have a new drupal 10 site that I works great and has a views page set as the home page. When i install the redirect module the home break breaks with this same error. In addition the home page links in breadcrumbs and admin toolbar dont have a link or go the wrong place. If I uninstall redirect module it all works as expected.

    Let me know if there is anything further I can test to help you discover the issue.

  • 🇮🇳India Bala.addweb

    This patch adds a validation check in the RedirectForm itself to ensure that the redirect URL is not empty. If the URL is empty / invalid, it sets a form error with the message: "Invalid redirect URL. Redirect URL can't be empty."

  • Status changed to Needs review 5 months ago
  • 🇮🇳India chaitanyadessai Goa

    Redirect To field is required field hence it doesn't required validations to check if the redirect URL is empty .

  • 🇮🇳India Bala.addweb

    Redirect To field is required field hence it doesn't required validations to check if the redirect URL is empty .

    Hi, Although the "Redirect To" field is a required field, it currently accepts , which results in an empty URL after saving. Therefore, we need this additional validation to ensure that the redirect URL is not empty or invalid, even when is used.
    Thanks.

  • 🇨🇭Switzerland handkerchief

    Redirect to the frontpage seems impossible. I tried with "", with "/node/some-id", it always give me this error:

    InvalidArgumentException: Cannot redirect to an empty URL. in Symfony\Component\HttpFoundation\RedirectResponse->setTargetUrl() (Zeile 68 in /webroot/vendor/symfony/http-foundation/RedirectResponse.php).

    #0 /webroot/web/core/lib/Drupal/Component/HttpFoundation/SecuredRedirectResponse.php(60): Symfony\Component\HttpFoundation\RedirectResponse->setTargetUrl('')
    #1 /webroot/vendor/symfony/http-foundation/RedirectResponse.php(39): Drupal\Component\HttpFoundation\SecuredRedirectResponse->setTargetUrl('')
    #2 /webroot/web/core/lib/Drupal/Core/Routing/TrustedRedirectResponse.php(26): Symfony\Component\HttpFoundation\RedirectResponse->__construct('', 301, Array)
    #3 /webroot/web/modules/contrib/redirect/src/EventSubscriber/RedirectRequestSubscriber.php(170): Drupal\Core\Routing\TrustedRedirectResponse->__construct('', '301', Array)
    #4 [internal function]: Drupal\redirect\EventSubscriber\RedirectRequestSubscriber->onKernelRequestCheckRedirect(Object(Symfony\Component\HttpKernel\Event\RequestEvent), 'kernel.request', Object(Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher))
    #5 /webroot/web/core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php(111): call_user_func(Array, Object(Symfony\Component\HttpKernel\Event\RequestEvent), 'kernel.request', Object(Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher))
    #6 /webroot/vendor/symfony/http-kernel/HttpKernel.php(157): Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch(Object(Symfony\Component\HttpKernel\Event\RequestEvent), 'kernel.request')
    #7 /webroot/vendor/symfony/http-kernel/HttpKernel.php(76): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1)
    #8 /webroot/web/core/lib/Drupal/Core/StackMiddleware/Session.php(53): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #9 /webroot/web/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(48): Drupal\Core\StackMiddleware\Session->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #10 /webroot/web/core/lib/Drupal/Core/StackMiddleware/ContentLength.php(28): Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #11 /webroot/web/core/modules/big_pipe/src/StackMiddleware/ContentLength.php(32): Drupal\Core\StackMiddleware\ContentLength->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #12 /webroot/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(106): Drupal\big_pipe\StackMiddleware\ContentLength->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #13 /webroot/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(85): Drupal\page_cache\StackMiddleware\PageCache->pass(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #14 /webroot/web/modules/contrib/shield/src/ShieldMiddleware.php(263): Drupal\page_cache\StackMiddleware\PageCache->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #15 /webroot/web/modules/contrib/shield/src/ShieldMiddleware.php(130): Drupal\shield\ShieldMiddleware->bypass(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #16 /webroot/web/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(48): Drupal\shield\ShieldMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #17 /webroot/web/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(51): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #18 /webroot/web/core/lib/Drupal/Core/StackMiddleware/AjaxPageState.php(36): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #19 /webroot/web/core/lib/Drupal/Core/StackMiddleware/StackedHttpKernel.php(51): Drupal\Core\StackMiddleware\AjaxPageState->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #20 /webroot/web/core/lib/Drupal/Core/DrupalKernel.php(741): Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #21 /webroot/web/index.php(19): Drupal\Core\DrupalKernel->handle(Object(Symfony\Component\HttpFoundation\Request))
    #22 {main}

    Redirect to another node, which is not defined as frontpage in "/admin/config/system/site-information" is working. It seems that one problem is, that will trigger empty url error.

    Core: 10.3.2
    Redirect: 8.x-1.10

  • 🇨🇭Switzerland handkerchief

    After this error, I had do uninstall the whole module, because when I'm going to the frontpage, this error appears again and again, although I've deleted all redirects, rebuild cache etc.

  • 🇨🇭Switzerland handkerchief

    Ok forget my posts, I found the reason: https://www.drupal.org/project/drupal/issues/2972344#comment-15408830 🐛 InvalidArgumentException: Cannot redirect to an empty URL. in Symfony Active
    It was the exact same situation in my scenario. All good.

Production build 0.71.5 2024