title: use https only for login page not the whole website
body: <p><br>
            i want to open login page of my website with <code>https</code> only,not the comeplete website. after login authenication ( successful), website whoud again run on <code>http</code>.</p>
  
  <p>currently  my main login page is <code>test_index.php</code> where i included <code>test_header.php</code></p>
  
  <p>my basic code on <code>test_header.php</code> is </p>
  
  <pre><code>if($_SERVER['SERVER_PORT'] != 443) {
     header("HTTP/1.1 301 Moved Permanently");
     header("Location: https://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
     exit();
  }
  </code></pre>
  
  <p>but this make complete website in <code>https</code><br>
   i also read <a href="http://www.vbulletin.com/forum/showthread.php/230420-https-for-login-only" rel="nofollow">here</a> that it can be possible via <code>.htaccess</code>, so i remove above code snippet from <code>test_header.php</code> and add the following lines in <code>.htaccess</code> file and </p>
  
  <pre><code>&lt;IfModule mod_rewrite.c&gt;
    RewriteEngine on
    # 301 redirect to domain to 'www.'
    RewriteCond %{HTTP_HOST} ^testweb.com$ [NC]
    RewriteRule ^(.*)$ http://www.testweb.com/$1 [R=301,L]
  &lt;/IfModule&gt;
  
  &lt;FilesMatch test_index.php&gt;
  RewriteEngine on
  RewriteCond %{HTTPS} !=on
  RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R,L]
  &lt;/FilesMatch&gt;
  </code></pre>
  
  <p><em>Note: testweb.com is just an imaginary name, not actual website</em></p>
  
  <p>but still complete website run on https, please tell me where i m doing mistake??</p>
  
  <h1>Edit</h1>
  
  <p>@webbiedave please check my <strong>updated Code</strong> , is that right way?? </p>
  
  <pre><code>if ($_SERVER['REQUEST_URI'] == '/test_index.php') { // only check https on login
      if (isset($_SERVER['HTTPS']) &amp;&amp; $_SERVER['HTTPS'] == 'on') {
          header("HTTP/1.1 301 Moved Permanently");
          header("Location: https://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
          exit();
      } else {
          die("Sorry,Your website is not secure");        
      }
  } elseif (isset($_SERVER['HTTPS']) &amp;&amp; $_SERVER['HTTPS'] == 'on') {
          // header("HTTP/1.1 301 Moved Permanently");
          header("Location: http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
          exit();
  }
  </code></pre>
  
  <p>Thanks</p>