2

on some forms I added custom redirects, for example on the user login form:

function my_module_user_login_submit(&$form, \Drupal\Core\Form\FormStateInterface $form_state) {
  $form_state->setRedirect('view.my_custom_view.page_1');
}

This is working well even with https on my test server: the user will be redirected after login to the view page with https, let's say https://my-domain.de/my-view-page

On another server the same is not working: on this server the domain is only reachable via https - not via http. This means calling http://my-domain.de will lead to a server error only using https://my-domain.de the project will be displayed. Now when I login I will be redirected to http://my-domain.de/my-view-page (without https) which leads to this server error.

I am sucessfully logged in: when I enter https://my-domain.de/my-view-page manually I can reach this know. When logout (I did not any changes here) the same appears: After logout the user gets redirected to http://my-domain.de.

Can somebody give me a hint what can be the problem on the second server?

Best, Tobias

5
  • Check in settings.php the section "Reverse Proxy Configuration".
    – 4k4
    Jun 15 '18 at 14:42
  • As the web root is never reached via http no changes in .htaccess or settings.php can help Jun 18 '18 at 7:07
  • Try var_dump(\Drupal::request()->server->all()); on the second server and check for headers of a CDN.
    – 4k4
    Jun 18 '18 at 7:39
  • The Drupal project is behind an AWS load balancer... I think this might be the hot tip... Jun 18 '18 at 7:51
  • OK, then you only need to tell Drupal to trust this reverse proxy in settings.php.
    – 4k4
    Jun 18 '18 at 7:55
1

On another server the same is not working: on this server the domain is only reachable via https - not via http

Perhaps a redirect to force HTTPS was not set up on your other server.

see Enabling HTTP Secure (HTTPS). You can do this by altering the VirtualHost definitions on your 2nd server:

<VirtualHost *:80>
    ServerName www.example.com
    Redirect "/" "https://www.example.com/"
</VirtualHost>

or alternatively you can do it in the .htaccess file by adding:

RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
3
  • This adds a redirection and does not solve the core of the question: why I Drupal creating redirects to a non https URL? If Drupal would create the correct redirects there would be no need to do this redirect Jun 18 '18 at 7:02
  • PS: in .htaccess I cannot set this as I do not reach the web root folder calling the domain without https Jun 18 '18 at 7:06
  • @TobiasKrause Didn't you ask Can somebody give me a hint what can be the problem on the second server? you never asked why Drupal is creating redirects to non https url... Also, you say, This means calling http://my-domain.de will lead to a server error this is bad practice, it should redirect to https. In addition, if all is well on your test server, this most likely means Drupal is not the issue, and it's probably a server configuration issue on your other server. Like not doing what my answer says.
    – No Sssweat
    Jun 18 '18 at 7:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.