Questions tagged [redirection]

Redirection in Drupal means sending the users to a different page.

Filter by
Sorted by
Tagged with
24 votes
14 answers
13k views

How do I hide the default page /node?

Drupal out of the box comes with a page (which is the default homepage) that is assigned to the node path. How do I avoid users reach it, and redirect them to the actual homepage of the site?
user avatar
  • 5,270
20 votes
7 answers
44k views

Redirect after form submission

I created a custom form in Drupal 8. I remember we can redirect to custom path in Drupal 7 with $form_state['redirect'] = 'mycustompath'; in a submission handler. How can I achieve the same in Drupal ...
user avatar
  • 21k
20 votes
3 answers
18k views

Form Redirect not working if 'destination' is in URL

In one of my forms, I'm trying to set a $form_state['redirect'] so the form will go to that destination after the user clicks one of the action buttons. If I inspect $form_state['redirect'] both ...
user avatar
  • 5,453
20 votes
1 answer
11k views

What API function do I use for redirecting to external URLs?

When writing a module, for redirecting to Drupal paths, one uses drupal_goto. Is there some API function that I should use for redirecting to external pages? Or is setting the Location with ...
user avatar
18 votes
4 answers
12k views

Redirect Anonymous user to login page

I want if user not logged in and visit any page of my website except my REST VIEWS routers I redirect him/her to login page in drupal 8, I found this solutions for drupal 7 but didn't find any ...
user avatar
17 votes
9 answers
38k views

What function/method can I use to redirect users to a different page?

In Drupal 7, I use the following code. function my_goto($path) { drupal_goto($path, array(), 301); } What code should I use in Drupal 8?
user avatar
17 votes
2 answers
39k 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 ...
user avatar
  • 193
16 votes
0 answers
11k views

How do I perform a redirect to a custom URL after login? [duplicate]

I am trying to redirect users to a custom URL after they logged in, but my code doesn't work. How do I redirect users after they logged in?
user avatar
  • 305
14 votes
18 answers
29k views

Redirect after user login

I would like to redirect users after they log in. Is it possible to use hook_user_login() to make the redirection? How do I add the parameter for the redirection?
user avatar
  • 311
14 votes
8 answers
13k views

How to redirect an anonymous user to the login form after a 403 error?

I want to redirect an anonymous user to the login form if such user encounters a 403 error. I have created event subscriber and this is my code, but I end up on loop on the current page. /** * ...
user avatar
14 votes
4 answers
17k views

Redirect to a custom page after a node has been added or edited

Using hook_form_alter, how can I redirect a user to a a custom page after creating or editing a node instead of the node that was created or edited? The current code for hook_form_alter() is the ...
user avatar
  • 7,884
13 votes
6 answers
16k views

Redirect user after node add/edit

I want to redirect users to a custom page, after they create a node or edit it.
user avatar
  • 325
12 votes
4 answers
4k views

How include hash (#) in drupal_goto path?

Is there any way to include a # in drupal_goto? i want something like this function MYMODULE_preprocess_node(&$variables) { $node = $variables['node']; switch ($node->type) { case '...
user avatar
  • 1,357
12 votes
5 answers
14k views

How to perform a redirect to custom page after node save or delete?

What I'm trying to do doesn't work, I still get redirected to /node/{id}: function hook_form_alter(&$form, $form_state, $form_id) { $form['actions']['submit']['#submit'][] = '...
user avatar
  • 136
11 votes
8 answers
15k views

Path alias creates redirect loop or redirects to the front page

When I call our sit "www.example.com/contact-us" I'm getting the following error: Oops, looks like this request tried to create an infinite loop. We do not allow such things here. We are a ...
user avatar
  • 163
11 votes
2 answers
4k views

Force redirect in submit handler even though destination parameter set

I add a custom submit handler and now I want Redirect to custom route after form submitted. This is what I used use Drupal\Core\Form\FormStateInterface; use Symfony\Component\HttpFoundation\Request;...
user avatar
  • 21k
10 votes
4 answers
16k views

How to do a RedirectResponse with a destination query parameter?

This works: $redirectURL = '/cart/add/p2'; return new RedirectResponse(base_path().$redirectURL); The problem is, I want this: $redirectURL = '/cart/add/p2?destination=somewhere'; The moment I ...
user avatar
  • 1,011
9 votes
2 answers
13k views

Redirect to the front page with a different language

i have a question about redirecting to a page with a different language. I found this old post for drupal 7 but I doesn't really help me - https://www.drupal.org/node/1280468 Now we are in Drupal 8 ...
user avatar
  • 657
9 votes
1 answer
4k views

How to redirect to external URL upon form submission

I've extended a FormBase and I've defined the submitForm method. In this method I want to redirect to an external URL (https://example.com/my/path?amount=33&gift=0&product_id=1) $myurl = "...
user avatar
  • 667
8 votes
3 answers
10k views

301 Redirect Module [closed]

I need to redirect specific broken/dead links to other pages within my site. I'm looking for a module that I can setup, then have my support team change without needed htaccess, etc. I came across ...
user avatar
8 votes
4 answers
15k views

Is it possible to redirect after "pushing" a file to the user?

I've got a setup where a site generates internal analytics about site usage. Users are able to request a download of their personal analytics, and because this information is sensitive I do not create ...
user avatar
8 votes
2 answers
1k views

How to avoid Drupal redirecting my multilingual Views pages?

I've got a Views page in a multilingual website where I need a different url for each language, ie: es: mysite/apartamentos. en: mysite/appartments. fr: mysite/appartements. ru: mysite/arendu. I ...
user avatar
8 votes
3 answers
4k views

TrustedResponseRedirect failing - how to prevent cache metadata?

I am getting the following when trying to redirect to an external site from my controller function defined in my routing file: return new TrustedRedirectResponse($my_ext_url); LogicException: The ...
user avatar
  • 273
8 votes
2 answers
2k views

Would redirecting users in hook_menu's access callback have any undesirable effects?

This answer led to a discussion about the best way to redirect a user to a specific page if they shouldn't have access to the page they are trying to access. One option is to set the access callback ...
user avatar
  • 6,373
7 votes
2 answers
4k views

Making drupal_goto Ignore ?destination=foo

I frequently come across cases in my Drupal 6 sites where a user might encounter my module's pages with the ?destination=foo querystring appended to the URL, from previous interactions on the site. ...
user avatar
7 votes
3 answers
4k views

How can I turn off caching redirect?

I have a url that would normally redirect to a specific page, however, some code is run prior to this. I am returning a RedirectResponse instance, and it appears to be being cached. How can I force ...
user avatar
  • 143
7 votes
1 answer
9k views

How to redirect to frontpage from a controller

Right now I'm doing this ugly thing to get the url of the my set frontpage (skipping validations and making sure it exists since I'm not sure if I'll even use this approach) $url = $this->config('...
user avatar
6 votes
8 answers
16k views

How do I redirect users and show a message?

I want to redirect users with RedirectResponse and display a message, but the message is not displayed. $response = new RedirectResponse($url); $response->send(); After little debugging I found ...
user avatar
  • 2,389
6 votes
2 answers
5k views

How to use the Rules module to implement a custom redirect for an outdated URL?

I used to show content from a catalog via the Views module, accessing an external database, so that all of the URLs would be something like /content?name=[name]. For various reasons, I've opted to ...
user avatar
  • 75
6 votes
7 answers
12k views

How to redirect toward a specific node from front-page in Drupal 7?

I have a multi language site made in Drupal 7. And I want to check if I am on the front page then if true to redirect the user to a to some specific node. I have tried different methods: to create ...
user avatar
  • 4,350
6 votes
3 answers
13k views

How do I get parameters from form redirect?

I've made a form and I'm trying to get the submit result into a redirect page with URL api: public function submitForm(array &$form, FormStateInterface $form_state) { $metier=$...
user avatar
  • 2,410
6 votes
2 answers
3k views

$form['redirect'] = "something=$someId"; doesn't work in Drupal 7

I am here again with a problem! I want to make a form redirect usign a url with ids and somethings else as parameter, but when the code is executed something encode my url, so, if I put something like ...
user avatar
6 votes
2 answers
3k views

How to redirect user page to front page for specific roles

I want to redirect every users page to front page? like if user page url is /user/97 then it redirect to front page if user is not administrator. I want user page inaccessible to other users but only ...
user avatar
  • 173
6 votes
1 answer
7k views

form_state->setRedirect(to_a_new_node_page) from the submitForm function, route "does not exist" issue

I created a custom module, It generate a custom Form in a page. When I submit my form, I create a new node. So, I am redirect to the form page but I would like be redirect to the new node page. I add ...
user avatar
  • 1,269
6 votes
3 answers
4k views

RedirectResponse not working

I'm in the process of porting my modules from D7 to D8. No real problems so far, but... I have a multistep form from where I need to redirect to /node/add/xyz in the last step. (All required input ...
user avatar
  • 61
6 votes
2 answers
3k views

Is there a way to create a taxonomy path redirect?

I am trying to create a taxonomy redirect for specific taxonomy URL. Basically what Taxonomy Redirect did for Drupal 6 but for Drupal 7. I have searched the Drupal 7 API for hook_term_path but don't ...
user avatar
6 votes
4 answers
2k views

How to prevent a node being saved when using the Rules module?

Is it possible to prevent a node from being saved with Rules? This is what I do now: Create a rule Before saving content of type ''. Condition: IF ... TRUE => Redirect & set message Create a ...
user avatar
  • 776
5 votes
4 answers
766 views

Redirect on Login?

I have tried making this a rule as well as used hook_user with no luck. It definitely gets inside of the login case (had a watchdog log), but the redirect doesn't happen and they are still sent to /...
user avatar
  • 26.8k
5 votes
5 answers
3k views

How can I redirect users upon login sometimes but not break the "Forgot password?" function?

I'm using Rules to redirect users with certain roles upon login using the Page Redirect action. The "Force redirect" option is set to true (changing this to false does not fix the problem, and if it ...
user avatar
5 votes
3 answers
1k views

How to restrict access to a node via node/12 and allow access via a path like content/sometitle?

Problem: I want to restrict direct node access using node number www.example.com/node/12 and allow access using pathauto alias www.example.com/content/sometitle to anonymous user. This user should be ...
user avatar
  • 51
5 votes
5 answers
10k views

Redirect contact form on submit

Using Drupal 8 and trying to get the contact form to redirect to the same page after submitting. By default it seem to redirect to the home page. I have edited my themename.theme file function ...
user avatar
5 votes
4 answers
908 views

How to get the content owned by the currently logged-in user?

A user is the owner of only one node, and I want to redirect the user, at login time, to his only owned node. How can I get the node content if I know only the logged-in user?
user avatar
  • 4,350
5 votes
1 answer
4k views

EventSubscriber endless redirect

I have Drupal 8.5.1 and I am trying to force a redirect for anonymous users to the CAS login page. First I thought that the issue was related with the firing of the checkAuthStatus function below, ...
user avatar
  • 326
5 votes
2 answers
3k views

How to alter node url or toUrl function output?

How do we alter what's returned from $node->url()? or $node->toUrl()? There are many entity reference fields that don't allow referencing more than one entity type or a custom route, such as entity ...
user avatar
  • 13.5k
5 votes
1 answer
3k views

How do I pass a variable via drupal_goto()?

So I have a function having http://link/to/$id as destination link. It works when I use <a href="?q=mymodule/option/$id">Targeted</a>. But I need to change it to submit form because I ...
user avatar
5 votes
2 answers
359 views

Build StackExchange-style url's

I'm looking for a way to build what I call 'StackExchange style' url's with Drupal 7. In my definition, that means: A node has a path alias containing both a unique identifier and the node title. For ...
user avatar
  • 14.9k
5 votes
4 answers
2k views

Login fails due to loop on localhost. Any ideas why?

I have git cloned a site and used Backup and Migrate to bring the database over the the local host. Working on the remote host the login works fine. Not locally. Well not anymore it worked for about ...
user avatar
5 votes
1 answer
503 views

How do I include ? and = in a form redirection?

I have a form and I would like to take the value from it, and use it as input for a page view which is created using exposed filters. I have created a submit handler for my first form. I then redirect ...
user avatar
5 votes
2 answers
4k views

using drupal sessions during hook_boot

When a user calls the front page of our site we want to check the country from which the user is surfing and redirect the user directly to the country specific front page. We chose to use the ...
user avatar
  • 163
5 votes
1 answer
3k views

One time login redirect to password change page

In D7, How can i redirect the user when he/she use One time login. My target is after clicking one time login button user has to redirect to change password. Can any one help on this.....
user avatar
  • 339

1
2 3 4 5
17