Linked Questions

0 votes
1 answer
115 views

Why does RedirectResponse not work on production server?

I have a very simple custom block/form that takes a user id and jumps to their profile page. The form submitForm has this: $uid = $form_state->getValue('uid'); $path = '/user/' . $uid; $response = ...
1 vote
1 answer
291 views

How can I programmatically trigger a 403 error with a hook implementation?

In a module within a drupal hook I'd like to conditionally trigger a 403 for the user. I could archieve this e. g. by throwing an exception throw new \Symfony\Component\HttpKernel\Exception\...
0 votes
0 answers
452 views

Status messages don't show

I have a controller that manages a password reset form submit. Everything works fine, except for setting messages. I've tried to alter the message in the .module file too with no luck. It worked on ...
0 votes
1 answer
673 views

Site stuck in 'headers have already been sent' login loop after D9 upgrade

Suggestions for debugging a site which is now stuck in a "headers have already been sent" loop after successful login (redirect back to login form)? This is a production server for a site ...
5 votes
1 answer
380 views

In a hook, how can I distinguish between web users and JSON:API users?

I have a Drupal website that also hosts an Ionic app via JSON:API. I want website users to be redirected on entity insert, so I added a redirect like this: function MYMODULE_flagging_insert(...
5 votes
1 answer
2k views

Disabling Page Cache for Redirect Response

I've implemented a conditional redirect on my site via an event subscriber and returning a redirect response. It's working but, I believe due to the page_cache module is getting cached for anonymous ...
4 votes
1 answer
1k views

Redirection cached?

I have 2 versions of site (with same code), one for Switzerland (.ch) and other for rest of the world (.com). What I need is that if someone from Switzerland visits .com is redirected to .ch And other ...
17 votes
2 answers
45k views

How to create a redirection programmatically? [closed]

I try to create a redirection 301 with the redirect module. For example, I want to redirect an URL source to an internal URL through my custom module. I want to create a redirection when I create a ...
1 vote
2 answers
985 views

How to redirect after node insert (not form redirect)?

I am trying to find out how to redirect after I insert a new node. All the answers I have been able to find discuss $form_state->setRedirectUrl(); but this is a form redirect; not a proper redirect ...
0 votes
2 answers
2k views

Why 'Failed to start the session' when RedirectResponse is sent?

When this code is executed, I have an error message logged. The code is in shared_node_access(NodeInterface $node, $op, AccountInterface $account) if ($node->get('nid')->value == 1) { if ($...
2 votes
1 answer
2k views

How do I redirect in a class sub-classing the EventSubscriber class?

I want to redirect to a specific URL in an EventSubscriber class instead of showing the Page not found page. I followed Symfony2 redirect for event listener? but the redirect goes to the home. This ...
2 votes
3 answers
3k views

How do I redirect users to an external URL?

I implemented a controller class in Drupal 8, which redirects to an external site. If I use \Symfony\Component\HttpFoundation\RedirectResponse, I get this error. Redirects to external URLs are not ...
4 votes
1 answer
489 views

Different front page depending on previous selection for anonymous users

I have a D8 project where the client wants users to select a route they will follow depending on who they are (let's call the two groups Students and Employers), and then the next time they visit show ...
0 votes
1 answer
1k views

Redirect users to an external URL

Is it possible to redirect users from a controller? I tried using the following code, but it doesn't work. public function hello() { $query = $db->select('coop.oad','x'); $query->fields('...
5 votes
1 answer
3k views

Invalidate node cache so hook_node_view() runs on each node view

My module uses hook_node_view() to add some contents to the node view. function example_node_view() { if ($view_mode == 'full' && $node->bundle() == 'example') // Insert file listing ...