Skip to content

Instantly share code, notes, and snippets.

View cherouvim's full-sized avatar

Ioannis Cherouvim cherouvim

View GitHub Profile
@cherouvim
cherouvim / gist:9e8721ef4a9589fd36e1c7a4be419fe9
Last active May 13, 2021 16:56
do not lose facebook likes when migrating your wordpress site from HTTP to HTTPS
# 1) Disable any automatic http to https redirect on your proxy or hosting provider. Both http and https traffic should reach your .htaccess so you control redirects from there.
# 2) .htaccess should redirect facebook's bot to http, and everyone else to https.
RewriteEngine on
RewriteCond %{REQUEST_SCHEME} ^https$
RewriteCond %{HTTP_USER_AGENT} facebookexternalhit/[0-9]
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{REQUEST_SCHEME} ^http$
RewriteCond %{HTTP_USER_AGENT} !facebookexternalhit/[0-9]
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]