Drupal 7 Webform自定义URL失效自动跳转至首页求助
Hey Matt, sorry to hear your Drupal Webform's custom redirect URL is acting up—let's walk through some common fixes to get this sorted out, since you mentioned it worked before (so something must have changed recently):
First, double-check the core settings (easy to overlook!)
Head to your Webform's configuration → Form settings → Redirect behavior. Make sure:
- You've selected "Redirect to URL" (not "Show confirmation message" or "Redirect to front page")
- The custom URL is correctly formatted: no typos, includes a leading slash (like
/thank-you-pageinstead ofthank-you-page), and any tokens you're using (e.g.,[webform_submission:values:user_email]) are valid. Try a static URL first to rule out token problems.
Check for custom code or module interference
Since it worked before, a recent code change or module update might be overriding the redirect:
- Look for custom hooks like
hook_webform_submission_insert()orhook_webform_submission_update()in your custom modules. If you see code that forces a redirect to the front page (like$response = new RedirectResponse(\Drupal::url('<front>'));), comment it out temporarily to test. - Disable any contributed modules that modify Webform behavior (like Webform Rules, workflow modules, or custom submission handlers) one by one to see if the redirect starts working again.
Clear Drupal's cache (it's often the culprit!)
Drupal's cache can hang onto old configuration settings. Clear all caches either via Drush:
drush cr
Or through the UI: Go to Configuration → Performance → Clear all caches. Test the form right after clearing.
Verify the submission's redirect value in the database
If the redirect still fails, check the webform_submission table in your database for your test submission. Look at the redirect column—it should show your custom URL. If it's empty or set to <front>, that means the setting isn't saving properly. Check if you have the right permissions to edit Webform configurations, or if a module is altering the form settings before they're saved.
Test with a fresh Webform
Create a simple test Webform (just a text field and submit button), set a custom redirect URL, and submit it. If this works, the issue is specific to your original Webform—maybe its configuration got corrupted, or there's a conflict with a specific field/handler. Try rebuilding the original form step by step or exporting/importing its config to a clean environment to isolate the problem.
If none of these steps fix it, sharing your Drupal version, Webform version, and any recent changes (module updates, code deployments) would help narrow things down further.
内容的提问来源于stack exchange,提问作者Matt Matt M

