Questions tagged [redirection]

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

Filter by
Sorted by
Tagged with
5
votes
3answers
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 ...
6
votes
4answers
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 ...
14
votes
19answers
26k 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?
6
votes
2answers
4k 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 ...
3
votes
1answer
793 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 ...
13
votes
8answers
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. /** * ...
16
votes
0answers
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?
20
votes
3answers
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 ...
17
votes
9answers
33k 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?
6
votes
1answer
6k 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 ...
22
votes
14answers
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?
17
votes
2answers
37k 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 ...
17
votes
4answers
11k 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 ...
3
votes
3answers
6k views

How can I redirect node page for a content type to custom URL?

I need to redirect all the pages for a content type to a custom URL in Drupal 8. I used to do this in Drupal 7 by implementing hook_init() with the function drupal_goto() or by using the Rules module....
20
votes
1answer
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 ...
13
votes
6answers
15k views

Redirect user after node add/edit

I want to redirect users to a custom page, after they create a node or edit it.
3
votes
1answer
2k views

Redirect based on query string

I'm migrating a legacy blog from a home-grown CMS to Drupal 7 and I need to wrap my head around how I'm going to redirect URLS to a new aliased pattern. The legacy site's URLs use query strings /?t=...
3
votes
2answers
410 views

How to implement a Rules Condition like [account:last-login] = never?

Here is my contextual explanation: I would like to redirect on a special page for first time after login. But registering system is using an email validation, so the path to the first login is "user/...
2
votes
1answer
89 views

How to automatically skip intermediate redirects?

I've run into the issue where I end up with something like this: about-us01 --> about-us02 --> about-us The correct path is "about-us". But due to admins changing things I have ended up in a ...
2
votes
2answers
455 views

How to create a redirect to point to the user's id?

I'd like to create a redirect so when the user hits mydrupal.com/my-account its redirected to mydrupal.com/users/3 I'm using Pathauto and I know I can go to admin/config/search/path/add to add the ...
1
vote
5answers
2k views

drupal_goto ignored in custom form submit handler

I'm working on a site at the moment where some nodes are hidden behind a login. You can see a list of them, but to view them you need to sign in. The sign in is done by showing the user login block ...
5
votes
5answers
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 ...
11
votes
5answers
12k 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'][] = '...
8
votes
2answers
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 ...
4
votes
1answer
230 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 ...
8
votes
2answers
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 ...
3
votes
2answers
134 views

How to login-redirect users to their profile page on specific days only?

By using Rules Once per Day module, logged in user would be redirected to profile page on specific day. My issue is, every time when user logged in to the site, the user is redirected to profile page. ...
3
votes
2answers
6k views

Redirect anonymous user to login page

I need to redirect an anonymous user when they hit the url 'node/add/project' to 'user/login' - otherwise, just leave them enter that url. Not sure if I'm going about this the correct way (probably ...
3
votes
3answers
4k views

Redirect node form in D7

It looks like silly question but I'm really confused about redirection after node save and update. I tried to set $form['#redirect'] - without any success. I tried to set some other vars for instance:...
2
votes
1answer
2k views

How do I display a message after redirecting users from the logout page?

I'd like to show a message via drupal_set_message() after redirecting users from user/logout?destination=user. I tested this code but it doesn't work. if ($find) { drupal_set_message(t('This ...
2
votes
2answers
706 views

Redirect to a view with contextual filters

I would like to redirect the user to a view with some contextual filters on the submit of a custom form. For now I use this : $form_state->setRedirect('view.search.page_1', ['myvalue' => $...
20
votes
5answers
39k 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 ...
5
votes
2answers
5k views

How to redirect the user to a page and show a message on the admin overlay (using drupal_set_message and drupal_goto)

I need to redirect the user to a destination and show a confirmation/error message. How can I do that? This is my code: watchdog('webform', 'The user @user has been successfully created', array('@...
4
votes
1answer
7k views

Redirect node/id to node/path-auto-alias

Using Drupal 8 I need to set various links between my content types and so far I'm setting the link using their path-auto-generated-alias, but that's terrible practice because if I change the pattern ...
3
votes
2answers
2k views

Redirect all subpages back to the front page

I am trying to redirect everything that is under example.com/pictures back to the front page (i.e. I am hiding picture nodes to be directly viewable). Neither the Pathauto module nor the Global ...
3
votes
1answer
2k views

How to redirect based on views results?

I have a view that shows a list of nodes and has a contextual filter. If the number of nodes shown is only 1 then I want to redirect to that node page instead of showing the view. Can I do that in ...
2
votes
2answers
6k views

How to redirect URL with language prefix to the same URL with no prefix (default language)

I have installed i18n module so two languages Japanese and English are available. I have set Japanese to the default language and also "language Language negotiation" to "path prefix only". So all the ...
2
votes
2answers
5k views

How create Redirect pattern from old to new URLs?

D7: I'm going to update an articles path pattern (/articles/[node:uid] → /post/[new tokens]) but I need redirect users from old path to new one using tokens. And I don't know how to do that. I tried ...
1
vote
1answer
281 views

Redirect anonymous users to the register page

Is it possible to redirect anonymous user to user/register page? How can I do that?
1
vote
3answers
1k views

Redirect logged in (authenticated) users to a different frontpage using rules or php code

I need to always redirect authenticated users to a different page (to serve as their own frontpage) whenever they try to access the default (anonymous) frontpage. I want to achieve this using rules or ...
1
vote
1answer
198 views

How to get the uncached version of request headers?

We need to programmatically get the request headers using the mymodule_preprocess_page hook. To do this we tried the following, however, because we have CDN, Varnish, and Drupal Cache all enabled, the ...
0
votes
2answers
142 views

How to redirect a newly registered user to a custom URL after signing up?

By default after a new user signs up, a redirect to the home page happens. But in such case I want to redirect such user to another page like node/35. In this node/35 I then want to display some ...
6
votes
3answers
12k 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=$...
4
votes
4answers
26k views

How to redirect user to previous page after form submit?

I can redirect user after adding a node to any another page but would like to redirect them to previous page they were linked from. Now I use the following code: function ...
4
votes
2answers
3k views

Redirecting from example.com to example.com/drupal

I have Drupal 7 installed in a ./drupal directory in my web server (shared host). I would like www.mysite.net to be redirect to www.mysite.net/drupal in a transparent way for visitors. They should ...
4
votes
2answers
2k 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 ...
5
votes
2answers
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 ...
14
votes
4answers
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 ...
7
votes
2answers
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. ...
3
votes
1answer
1k views

How to make taxonomy terms link to an external site? [closed]

I am using the Lexicon module to automatically insert links to a vocabulary with information about words in the lexicon. But the vocabularies I am using are owned and hosted by a completely different ...