1

I want make an infinite series of 302 redirects. For example:

  • Visitor accesses example.com
  • Which 302 redirects to example.com/abc
  • Which 302 redirects toexample.com/xzy
  • Which 302 redirects to example.com/ghi
  • ... etc in an infinite loop with random URLs until timeout

I don't want Facebook bot to crawl my site. If I try to prevent it in the normal way, Facebook will still scrape text and images from my website. When my site is shared frequently on Facebook, I want my website to be blocked. If Facebook bot is stuck in redirect, it can not scrape my site.

  • 2
    Why would you ever want to do this? Most if not all modern browsers would detect a redirect issue and not even display any page and just tell the user the page is not redirecting properly. – Analog Apr 28 '16 at 11:31
  • 2
    There are much better and easier ways to stop FB from crawling your site. What does an "infinite" redirect achieve that a single redirect would not? The site you link to (which I've not checked in a browser - for fear of it being malicious) does something more that simply linking to "abc" and "xzy", it returns an enormous URL (which looks like they are trying to do something malicious). They probably are not using .htaccess. – MrWhite Apr 28 '16 at 11:53
  • you can try access this domain: agitz2016.com and use developers.facebook.com/tools/debug/og/object to scrap this domain, you will be see . . . – Sheng Long Apr 28 '16 at 11:56
  • 2
    "if make facebook bot stuck in redirect" - The FB bot won't get "stuck" in a redirect. It will simply detect the multiple redirect and error - as with a browser. Issueing multiple redirects also puts more work on your server. If you really need to block the request - block it on the first request. Fin. – MrWhite Apr 28 '16 at 11:56
  • 1
    You have already asked this on SO stackoverflow.com/questions/36910075/… – starkeen Apr 28 '16 at 15:07
2

i want to make infinite redirection because i dont want facebook bot crawl my site. if do in the normal way, the facebook also trace my website, and when I share in highly frequency mysite on facebook then my website will be blocked. if make facebook bot stuck in redirect it can not trace mysite – Sheng Long

That tactic'll work perfectly, if you want to kill your server. Simply put, their hardware won't even sweat and yours will give in and fail.

This is security through obscurity, which is not security. Please don't implement his, or similar ideas, ever.

You're apperantly looking for a work-around for Facebooks spam checks, for which I will not provide a better solution, sorry.

Check out the API tools, post via those, to a max of that limit. I don;t know how many posts you make, but I don't think you're using Facebook as is entended.

  • I just don't want facebook bot crawl my site, I'm not trying to spam on facebook. please guide me how to do in the .htaccess file – Sheng Long Apr 28 '16 at 12:23
2

I tried to add this into .htaccess file:

RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} (facebookexternalhit|FacebookExternalHit|Facebot) [NC]
RewriteRule ^(.*)$ ^$1 [R=302]

As already stated you don't "redirect", and certainly don't try to create an "infinite redirect", in order to block traffic. Purposefully creating an "infinite redirect" for any day-to-day webmastering is nonsensical.

Using robots.txt to block Facebook is probably the recommended way, but you mentioned in a comment on the duplicate question that you didn't want to use robots.txt for some reason.

So, based on your attempt, to block Facebook in .htaccess, the following should be sufficient:

RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} (facebookexternalhit|facebot) [NC]
RewriteRule ^ - [F]

This will return a "403 Forbidden" for all requests where the user agent contains either facebookexternalhit or facebot (NC - not case-sensitive).

Reference:
The Facebook Crawler - User Agents

in an infinite loop with random URLs until timeout

Just for info, this is probably not done in .htaccess. Apache config (ie. .htaccess) does not do "random".

  • 1
    Very helpful answer. Doesn't start with ridicule, corrects assumptions and then offers the resolve. Well done! – Vino Apr 29 '16 at 14:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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