Wamp Server 2 apache 2.4.2 drupal 7.14 redirect HTTP to HTTPS

Discussion in 'Apache' started by pichu, Jun 28, 2012.

  1. #1
    Hello everyone!

    I'm trying to force http://localhost/drupal to redirect to https://localhost/drupal.
    The installation folder of drupal is /wamp/www/drupal.

    For now I managed to have them both enabled. I followed the guide here http://developersdigest.blogspot.gr/2012/03/wamp-server-2-https-ssl-configuration.html
    I added
    DocumentRoot "C:/wamp/www/"
    Code (markup):
    to the httpd.conf file and added a virtual host to httpd-ssl.conf:

    <VirtualHost _default_:443>
    #   General setup for the virtual host
    DocumentRoot "C:/wamp/www/"
    ServerName localhost:443
    ServerAdmin admin@localhost
    # etc.
    
    Code (markup):

    With this setup, both http://localhost/drupal and https://localhost/drupal can be accessed.

    I tried to add several rules to httpd.conf, such as:

    
    RewriteCond   %{SERVER_PORT}  !^443$
    RewriteRule ^/?() https://%{HTTP_HOST} [R=301,L]
    
    Code (markup):
    but they either lead to "access forbidden" blank page or to the frontpage of my website reporting that some link (eg. https://localhost/drupal/drupal) can't be found.

    Any ideas?
     
    pichu, Jun 28, 2012 IP
  2. RoseHosting

    RoseHosting Well-Known Member

    Messages:
    230
    Likes Received:
    11
    Best Answers:
    11
    Trophy Points:
    138
    #2
    You can try with
    
    RewriteCond %{HTTPS} off
    RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
    Code (markup):
     
    RoseHosting, Jun 28, 2012 IP
  3. pichu

    pichu Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    This doesn't redirect either. Why %{HTTPS} off and not on?
     
    pichu, Jun 29, 2012 IP
  4. pichu

    pichu Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I changed the directories I use and managed to redirect from HTTP to HTTPS but I got access forbidden.
    I now have a /wamp/www directory with an index.php file with the following:
    <?php
    
    if($_SERVER["HTTPS"] != "on") {
       header("HTTP/1.1 301 Moved Permanently");
    header('Location: https://test.com');
       exit();
    }
    ?>
    
    Code (markup):
    This redirects requests to another directory (/wamp/drupal) which contains the original drupal index.php file:
    
    define('DRUPAL_ROOT', getcwd());
    require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
    drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
    menu_execute_active_handler();
    Code (markup):

    When I type http://test.com, it redirects to https://test.com/drupal with "You don't have permission to access /drupal/ on this server."
    Same when I type https://test.com, it gives "You don't have permission to access / on this server."

    I don't understand, access is forbidden by apache or drupal?
     
    pichu, Jun 29, 2012 IP