A
A
AlexMatovnikov2017-04-22 00:41:44
Apache HTTP Server
AlexMatovnikov, 2017-04-22 00:41:44

How to redirect only 1 page to HTTPS, the rest to HTTP?

Good evening!
There are following setting in .htaccess

DirectoryIndex index.php
ErrorDocument 404 /404.html
RewriteEngine On

RewriteRule ^basket$ /basket/ [R=301,L]
RewriteRule ^login$ /login/ [R=301,L]
RewriteRule ^reg$ /reg/ [R=301,L]
#
RewriteRule ^basket/(.*)$ index.php?do=static&page=basket [L]
RewriteRule ^login/(.*)$ index.php?do=static&page= login [L]
RewriteRule ^reg/(.*)$ index.php?do=static&page=reg [L]

How to make /basket/, /login/ and /reg/ pages accessible only via HTTPS protocol and go redirect if they are called over HTTP. And all other pages are HTTP only, even when they are accessed via HTTPS.

Example: how M.Video has a personal account, placing an order. When you go to your personal account via the http protocol, you are redirected to https. And when from there the user goes to any other page using the https protocol, he is transferred back to http

Thank you!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Arthur K., 2017-04-26
@amark

For example, you can add RewriteCond.
#Redirect to HTTPS
RewriteCond %{SERVER_PORT} !^443
RewriteRule ^basket/(.*)$ https://www.domain.com/ index.php?do=static&page=basket [L]
#Redirect to HTTP
RewriteCond %{ SERVER_PORT} ^443
RewriteRule ^(.*)$ www.domain.com/$1 [L,QSA] #here, specify the required transition url Upd.1. Note that the order of the rules is important. Because the second rule covers all pages, it needs to be set below. In the current example, if the first condition is met, then the first redirect will work, and then the execution will stop (due to the L index).
If the condition fails (the person does not go to the cart), then the second "general" condition will be applied.
Upd.2. By the way, it is not entirely clear why this is necessary? If there is a certificate for the site, then it is much more correct to distribute it to all pages, and not just to pages with personal information.
By the way: Google promotes sites with HTTPS in the issuance of https://hab... , https://security.googleblog.com/2016/09/moving-tow...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question