Skip to content

Instantly share code, notes, and snippets.

View andrewspear's full-sized avatar

Andrew Spear andrewspear

View GitHub Profile
@andrewspear
andrewspear / .htaccess
Last active December 21, 2015 08:28
Force specific sub-domains of a site to use SSL
# Force SSL for specific subdomains
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(secure|login)\. [NC]
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
@andrewspear
andrewspear / currentPageURL.php
Last active December 19, 2015 19:18
A simple PHP function to fetch the current page URL with PHP, .htaccess rewrites are respected and optionally you can exclude the query string, useful for creating canonical URLs.
<?
function currentPageURL($includeQueryString = true) {
$pageURL = 'http';
$pageURL .= ($_SERVER["HTTPS"] == "on") ? "s" : "";
$pageURL .= "://";
$pageURL .= ($_SERVER["SERVER_PORT"] != "80") ? $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"] : $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
if (!$includeQueryString) {
$pageURL = str_replace('?'.$_SERVER["QUERY_STRING"], '', $pageURL);
}