Https only on a specific page with .htaccess

I have a url for example http://www.domain.com/index.php?p=register. I want to redirect this use of HTTPS (SSL) with .htaccess, but only to this, and to a couple of other pages (login page, etc.), but not to the whole site. URLs do not point to directories, but are used to dynamically include different files.

Can someone give me a pointer or an example of how to get one page redirect to HTTPS?

Thank.

+2
source share
3 answers

Not htaccess, but another way could be to use PHP to redirect:

<?php

$redirectlist = array('register','login','myaccount');

if (in_array($_GET['p'], $redirectlist) && strtolower($_SERVER['HTTPS']) != 'on') {
    exit(header("location: https://{$_SERVER['SERVER_NAME']}{$_SERVER['REQUEST_URI']}"));
}

?>

, , , , htaccess. PHP- , (. header()).

+5

- :

RewriteEngine on
RewriteCond %{SERVER_PORT} !^443$
RewriteCond %{QUERY_STRING} (^|&)p=(register|login|or|other|protected|page)($|&)
RewriteRule (.*) https://www.domain.com/index.php [R=301,QSA,L]

:

  • , 443 ( ), .
  • ( ?) : p ,
  • , 301 , , ( , )
+3

php, . htaccess, , js nonSSL, , SSL.

+1

All Articles