2

I am in the final stage of updating a website and changed many url's for SEO purposes. Now I want to keep the social scores for most pages, most importantly the Facebook likes and comments. It has been confirmed that this is possible. See the following link for reference: How can I move a URL via 301 redirect and retain the page's Facebook likes and Open Graph information?

  • og:url on newurl.html page should be oldurl.html -> done
  • keep valid page with old og tags named oldurl.html -> done
  • redirect from oldurl.html to newurl.html -> done
  • exempt the Facebook crawler from this redirect -> I don't know how

I can't find an answer on how to this and there have been other people asking the same question with no answer. Only got purple links left on this subject and do not know what to do or search anymore.

How do does one stop a crawler from following a redirect?

Edit. I know now that this won't work this way but it is the best I can do. One of the conditions being don't be Facebook and then all the rules bundled together for that condition without having to repeat the condition for every rule:

RewriteCond %{HTTP_USER_AGENT} !facebookexternalhit/[0-9] RewriteCond %{HTTP_HOST} ^$ RewriteRule ^old-url1\.html$ http://domain.com/new-folder/new-url1.html? [N,R=301] RewriteRule ^old-url2\.html$ http://domain.com/new-folder/new-url2.html? [N,R=301] RewriteRule ^old-url3\.html$ http://domain.com/new-folder/new-url3.html? [L,R=301]

Edit2. I'll have to go with the repeat for every rule. Many url's changed name. Something more elegant might be possible but that is way beyond my ability. Does it have a significant influence on page load time if the code below is repeated 60 times with different url's?

RewriteCond %{HTTP_USER_AGENT} !facebookexternalhit/[0-9] RewriteRule ^old-url1\.html$ http://domain.com/new-folder/new-url1.html? [L,R=301]

Community
  • 1
  • 1
overlander
  • 21
  • 3
  • The accepted answer to that question already mentions the `User-Agent` header the FB scraper sends – so use that in a `RewriteCond` before the `RewriteRule` that does the redirecting. (If you don’t know how to use a `RewriteCond`, then go read the manual on that directive resp. research it first please.) – CBroe Jul 01 '15 at 16:27
  • You mean: `RewriteEngine on RewriteCond %{HTTP_USER_AGENT} !facebookexternalhit/[0-9]` That is how far I got. Then a `RewriteRule` is next but that is the part I can't figure out. I can block a crawler, ip range etc. but can't figure out how to "no follow 301", or "ignore 301". – overlander Jul 02 '15 at 00:01
  • Your `RewriteRule` has to do the 301 redirect – and via the `RewriteCond` you see to it that the RewriteRule does not get applied under certain circumstances. – CBroe Jul 02 '15 at 07:01
  • Thank you for your replies. Tried a variation of things but no luck. What I got so far: `RewriteCond %{HTTP_USER_AGENT} !facebookexternalhit/[0-9] RewriteCond %{HTTP_HOST} ^$ RewriteRule ^old-url1\.html$ http://domain.com/new-folder/new-url1.html? [N,R=301] RewriteRule ^old-url2\.html$ http://domain.com/new-folder/new-url2.html? [N,R=301] RewriteRule ^old-url3\.html$ http://domain.com/new-folder/new-url3.html? [L,R=301]` – overlander Jul 02 '15 at 09:01
  • Code in comments is hardly readable. Please edit your question to include what you have tried. – CBroe Jul 02 '15 at 09:59
  • `RewriteCond %{HTTP_HOST} ^$` – that seems to be pretty useless, the host name of the request will most likely not be empty. And yes, you will have to repeat the `RewriteCond` for every `RewriteRule`. Therefor if possible, you should use a rule that makes use of a _pattern_ to redirect multiple similar URLs at once, instead of having a single rule for each one. – CBroe Jul 02 '15 at 16:34

0 Answers0