7

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?

2
  • Check their user agent, if the HTTP_USER_AGENT matches facebook you can turn off rewite engine or just skip that rewite.
    – j_mcnally
    Oct 3, 2013 at 16:55
  • How do I check the FB opengraph useragent?
    – PF Billing
    Oct 3, 2013 at 17:01

1 Answer 1

11

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}
3
  • Should this still work ? I used this on a Joomla website which uses Cloudflare with force SSL but didnt work.
    – 9944990
    Sep 15, 2017 at 13:56
  • @9944990 The nature of CloudFlare's "Force SSL" is that CF tells the browser to redirect to HTTPS before your server has a chance to process those rules in the .htaccess. Therefore you would need to turn off "Force SSL" and let your .htaccess do the redirection.
    – hargobind
    May 9, 2018 at 7:54
  • I am adding same in my htaccess.. for now fb updates its not working Nov 12, 2019 at 6:58

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.