I would like to find a solution to switch between HTTP and HTTPS protocol on a PHP server and this solution have to works from a local network and from Internet network.
A scheme:
DNS: domain.com
IP: x.x.x.x <╌┬╌> IP: 192.168.1.1
┆
┌──────────┐ HTTP 80┌───┴────┐ HTTP 8000┌────────┐
│ INTERNET ╞══════════════╡ ROUTER ╞═══════════════╡ SERVER │ IP: 192.168.1.2
│ ╞══════════════╡ ╞═══════════════╡ │ DNS: SERVER.local
└────╥╥────┘ HTTPS 443└───╥╥───┘ HTTPS 8001└────────┘
║║ ║║
┌───╨╨───┐ ┌───╨╨───┐
│ CLIENT │ │ CLIENT │
└────────┘ └────────┘
The problem:
From local network, the client have to be redirected:
from
http://SERVER.local:8000
(port 8000 explicit) tohttps://SERVER.local:8001
(port 8001 explicit) or fromhttp://192.168.1.2:8000
tohttps://192.168.1.2:8001
From Internet network, the client have to be redirected:
from
http://domain.com
(port 80 implicit) tohttps://domain.com
(port 443 implicit) or fromhttp://x.x.x.x
tohttps://x.x.x.x
The question:
- How can I detect the origin of the client (Internet or local network) to switch him to the correct URL?
A global solution with IPv6 support too will be welcome! Thank you for your help.