Skip to content

Commit 6754361

Browse files
committed
Initial commit: Proxy-aware HTTPS plugin
0 parents  commit 6754361

3 files changed

Lines changed: 69 additions & 0 deletions

File tree

LICENSE

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
MIT License
2+
3+
Copyright (c) 2025 BitCryptic
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy...
6+

README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Proxy-Aware HTTPS Fix
2+
3+
A lightweight WordPress plugin that enforces HTTPS detection and correct REST API resolution when running behind reverse proxies like Caddy, Nginx, or Traefik.
4+
5+
## Features
6+
7+
- Forces `$_SERVER['HTTPS'] = 'on'` when proxy headers or domain heuristics indicate HTTPS
8+
- Rewrites `home_url()` and `site_url()` to always return `https://`
9+
- Ensures Rank Math SEO plugin uses the correct REST API base
10+
- Compatible with Dockerized WordPress stacks and reverse proxy setups
11+
12+
## Installation
13+
14+
1. Download or clone this repository into your WordPress `wp-content/plugins/` directory.
15+
2. Activate the plugin via the WordPress admin dashboard.
16+
17+
## Usage
18+
19+
No configuration required. The plugin auto-detects proxy headers and enforces HTTPS behavior.
20+
21+
## Author
22+
23+
**BitCryptic**
24+
Built by BitCryptic for scalable, proxy-aware WordPress deployments.
25+
26+
## License
27+
28+
MIT — see [LICENSE](LICENSE) for details.
29+

proxy-aware-https-fix.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
/**
4+
* Plugin Name: Proxy-Aware HTTPS Fix
5+
* Description: Enforces HTTPS detection and correct REST API resolution behind reverse proxies.
6+
* Version: 1.3
7+
* Author: BitCryptic
8+
*/
9+
10+
if (defined('WP_CLI') && WP_CLI) return;
11+
12+
add_action('plugins_loaded', function() {
13+
$host = $_SERVER['HTTP_HOST'] ?? '';
14+
$proto = $_SERVER['HTTP_X_FORWARDED_PROTO'] ?? '';
15+
16+
if (
17+
(!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] !== 'on') &&
18+
($proto === 'https' || strpos($host, '.') !== false)
19+
) {
20+
$_SERVER['HTTPS'] = 'on';
21+
}
22+
});
23+
24+
add_filter('home_url', function($url) {
25+
return str_starts_with($url, 'http:') ? 'https:' . substr($url, 5) : $url;
26+
});
27+
28+
add_filter('site_url', function($url) {
29+
return str_starts_with($url, 'http:') ? 'https:' . substr($url, 5) : $url;
30+
});
31+
32+
add_filter('rank_math/rest_api_url', function() {
33+
return get_site_url(null, '/wp-json/');
34+
});

0 commit comments

Comments
 (0)