Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exempt Facebook Crawler from .htaccess redirect

We recently forced all pages to be HTTPS through .htaccess:

RewriteEngine on
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

The problem is that I get "Circular redirect path detected" from Facebook debugger because the original URL is https, but the og:url is http (so we don't lose all of our old likes), and then it gets a 302 loop back to https.

How can I make Facebook an exception to this .htaccess rule?

like image 827
PF Billing Avatar asked Oct 03 '13 16:10

PF Billing


1 Answers

This question addresses the user-agent that facebook external hits will look like. You just need to add a condition to check for it:

RewriteEngine on
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_USER_AGENT} !facebookexternalhit/[0-9]
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
like image 115
Jon Lin Avatar answered Oct 29 '22 22:10

Jon Lin