Skip to content

Instantly share code, notes, and snippets.

@alexsoin
Last active April 6, 2017 07:25
Show Gist options
  • Save alexsoin/d7fc6884c7e89d6210c043b93f15f871 to your computer and use it in GitHub Desktop.
Save alexsoin/d7fc6884c7e89d6210c043b93f15f871 to your computer and use it in GitHub Desktop.
Плагин редиректа с http на https - modx plugin for OnHandleRequest to redirect from http to https
<?php
if ($modx->event->name != "OnHandleRequest") {return;}
$uri = $_SERVER['REQUEST_URI'];
if ($uri == '/robots.txt') return;
$url = $_SERVER['HTTP_HOST'];
$site_url = 'site.ru'; // replace with your domain
if ($url != $site_url || !$_SERVER['HTTPS']) {
$modx->sendRedirect('https://'.$site_url.$uri, array(
'responseCode' => 'HTTP/1.1 301 Moved Permanently')
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment