1

I'm running around in circles trying to get to the bottom of this problem, so hoping someone can help. In my module, I have the following in hook_menu():

<?php
  $items['test'] = array(
    'title' => t('Test Title'),
    'page callback' => 'test_page',
    'page arguments' => array(1, 2),
    'type' => MENU_CALLBACK,
    'access arguments' => array('access content'),
  );
?>

All is well with this and when I call http://www.mysite.co.uk/test I get everything I expect. However, when I call https://www.mysite.co.uk/test (note the https) it gets redirected to http://www.mysite.co.uk/index.php.

I have a rule in my .htaccess which forces paths that I don't want to be https to redirect to http.

  RewriteCond %{HTTPS} on
  RewriteCond %{REQUEST_URI} !(^/secure1.*|^/secure2.*|^/test.*)
  RewriteRule ^(.*)$ http://www.ebu.co.uk/$1 [R,L]

So if I enter https://www.mysite.co.uk/insecurepath it will (correctly) redirect to http://www.mysite.co.uk/insecurepath. This will return a drupal-handled 404 if necessary.

But I want URIs that go to /test to be secure, so https://www.mysite.co.uk/test is not being redirected.

But why is it then being redirected to index.php? Further on in .htaccess we have this rule:

  # Pass all requests not referring directly to files in the filesystem to
  # index.php. Clean URLs are handled in drupal_environment_initialize().

  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_URI} !=/favicon.ico
  RewriteRule ^ index.php [L]

This came from the drupal installation; I haven't touched it.

I assume my requests are reaching this point and being redirected to index.php. Is it unable to handle secure requests and just falls back to the front page? What can I do to be able to call my module's path with https?

2

I'm showing you a part of my .htaccess. I'm sending all traffic that enters my site via http:// to the https:// part.

Just add this at the bottom of your .htaccess:

RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTPS}s ^on(s)|
# This checks to make sure the connection is not already HTTPS
RewriteRule ^http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
#RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]
# This rule will redirect users from their original location, to the same location but using HTTPS.
# i.e. http://www.example.com/foo/ to https://www.example.com/foo/
# The leading slash is made optional so that this will work either in httpd.conf
# or .htaccess context

You may want to checkout the Secure Pages module. It allows you to select pages on your site that are to be HTTPS.

Your Answer

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